Submission #774802

#TimeUsernameProblemLanguageResultExecution timeMemory
774802scrgeKnapsack (NOI18_knapsack)C++17
0 / 100
6 ms12372 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int S = 2000; int s, n; multiset<int, greater<int>> vals[S+5]; 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:15:24: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   15 |       ((vals[w].size() == (s/w)+1 && v > *vals[w].lower_bound(v))
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~
knapsack.cpp:16:25: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   16 |       || vals[w].size() < s)){
      |          ~~~~~~~~~~~~~~~^~~
knapsack.cpp:17:25: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   17 |       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...