Submission #555607

#TimeUsernameProblemLanguageResultExecution timeMemory
555607DeMen100nsKnapsack (NOI18_knapsack)C++17
100 / 100
129 ms5772 KiB
/* Author : DeMen100ns (a.k.a Vo Khac Trieu) School : VNU-HCM High school for the Gifted fuck you adhoc */ #include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; const long long INF = 1e18 + 7; const int MAXA = 1e9; const int B = sqrt(N) + 5; vector <int> obj[N]; int dp[N]; void solve() { int s, n; cin >> s >> n; for(int i = 1; i <= n; ++i){ int v, w, k; cin >> v >> w >> k; k = min(k, s / w); int tmp = 1; while (k){ int V = v * tmp, W = w * tmp; obj[W].push_back(V); k -= tmp; tmp = min(tmp * 2, k); } } int ma = 0; for(int i = 1; i <= s; ++i){ sort(obj[i].begin(), obj[i].end(), greater<int>()); while (obj[i].size() > s / i){ obj[i].pop_back(); } for(int v : obj[i]){ for(int w = s; w >= i; --w){ dp[w] = max(dp[w], dp[w - i] + v); ma = max(ma, dp[w]); } } } cout << ma; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("codeforces.inp","r",stdin); // freopen("codeforces.out","w",stdout); int t = 1; // cin >> t; while (t--) { solve(); } }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:38:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         while (obj[i].size() > s / i){
      |                ~~~~~~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...