Submission #774787

#TimeUsernameProblemLanguageResultExecution timeMemory
774787scrgeKnapsack (NOI18_knapsack)C++17
0 / 100
4 ms6356 KiB
#include <bits/stdc++.h> using namespace std; const int S = 2000; int s, n; multiset<int, greater<int>> vals[S]; signed main(){ cin >> s >> n; for(int i = 0; i < n; i++){ int v, w, k; cin >> v >> w >> k; while(k-- && ((vals[w].size() == (s/w)+1 && v > *vals[w].lower_bound(v)) || vals[w].size() < s)){ if(vals[w].size() == s) vals[w].erase(prev(vals[w].end())); vals[w].insert(v); } } /* for(int i = 0; i < s; i++){ cout << i << ": "; for(int j: vals[i]) cout << j << " "; cout << endl; }*/ int dp[s+5][s+5]; memset(dp, 0, sizeof dp); for(int i = 1; i <= s; i++){ int cur_w = 0, cur_v = 0; for(int j = 0; j <= s; j++) dp[i+1][j] = dp[i][j]; for(int v: vals[i]){ cur_w += i, cur_v += v; if(cur_w >= s) break; for(int j = cur_w; j <= s; j++){ dp[i+1][j-cur_w] = max(dp[i+1][j-cur_w], dp[i][j]+cur_v); } } } int ans = 0; for(int i = 0; i <= s; i++) ans = max(ans, dp[s+1][i]); cout << ans << endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:14:24: warning: comparison of integer expressions of different signedness: 'std::multiset<int, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   14 |       ((vals[w].size() == (s/w)+1 && v > *vals[w].lower_bound(v))
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~
knapsack.cpp:15:25: warning: comparison of integer expressions of different signedness: 'std::multiset<int, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |       || vals[w].size() < s)){
      |          ~~~~~~~~~~~~~~~^~~
knapsack.cpp:16:25: warning: comparison of integer expressions of different signedness: 'std::multiset<int, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |       if(vals[w].size() == s)
      |          ~~~~~~~~~~~~~~~^~~~
#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...