Submission #3728175
Source Code Expand
#include <bits/stdc++.h> using namespace std; using ll = long long; int memo[4]; int main() { int n, W; cin >> n >> W; vector<vector<ll>> vv(4); for (int i = 0; i < n; ++i) { int w, v; cin >> w >> v; vv[w % 4].push_back(v); memo[w % 4] = w; } for (int i = 0; i < 4; ++i) { sort(vv[i].rbegin(), vv[i].rend()); for (int j = 1; j < vv[i].size(); ++j) { vv[i][j] += vv[i][j - 1]; } } for (int i = 0; i < 4; ++i) { vv[i].insert(vv[i].begin(), 0); } ll ans = 0; for (int i = 0; i < vv[0].size(); ++i) { for (int j = 0; j < vv[1].size(); ++j) { for (int k = 0; k < vv[2].size(); ++k) { for (int l = 0; l < vv[3].size(); ++l) { if (memo[0] * i + memo[1] * j + memo[2] * k + memo[3] * l <= W) { ans = max(ans, vv[0][i] + vv[1][j] + vv[2][k] + vv[3][l]); } } } } } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Simple Knapsack |
User | SinAyame |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 953 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 256 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 | AC | 1 ms | 256 KB |
antigreedy1 | AC | 1 ms | 256 KB |
antigreedy2 | AC | 1 ms | 256 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
example3 | AC | 1 ms | 256 KB |
quarter0 | AC | 2 ms | 256 KB |
quarter1 | AC | 2 ms | 256 KB |
quarter2 | AC | 2 ms | 256 KB |
rand0 | WA | 1 ms | 256 KB |
rand1 | WA | 1 ms | 256 KB |
rand2 | WA | 1 ms | 256 KB |
smallw0 | AC | 2 ms | 256 KB |
smallw1 | AC | 2 ms | 256 KB |
smallw2 | AC | 2 ms | 256 KB |