Submission #8523792
Source Code Expand
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int N; cin >> N; int MW; cin >> MW; int W0; vector<vector<int>> dp(N+1, vector<int>(3*N+1)); for (int i = 0; i < N; i++) { int w, v; cin >> w >> v; if (i == 0) W0 = w; assert(W0 <= w && w <= W0 + 3); w -= W0; for (int c = 0; c <= i; c++) { for (int t = 0; t <= 3 * i; t++) { dp[c+1][t+w] = max(dp[c+1][t+w], dp[c][t] + v); } } } int ans = 0; for (int c = 0; c <= N; c++) { for (int t = 0; t <= 3 * N; t++) { if (1ll * W0 * c + t <= MW) { ans = max(ans, dp[c][t]); } } } cout << ans << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Simple Knapsack |
User | ecnerwala |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 698 Byte |
Status | WA |
Exec Time | 3 ms |
Memory | 384 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2, example3 |
All | antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
antigreedy0 | WA | 3 ms | 384 KB |
antigreedy1 | WA | 3 ms | 384 KB |
antigreedy2 | WA | 3 ms | 384 KB |
example0 | AC | 1 ms | 256 KB |
example1 | WA | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
example3 | AC | 1 ms | 256 KB |
quarter0 | WA | 3 ms | 384 KB |
quarter1 | WA | 3 ms | 384 KB |
quarter2 | WA | 3 ms | 384 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |
smallw0 | AC | 3 ms | 384 KB |
smallw1 | AC | 3 ms | 384 KB |
smallw2 | WA | 3 ms | 384 KB |