Submission #866232

#TimeUsernameProblemLanguageResultExecution timeMemory
866232maks007Knapsack (NOI18_knapsack)C++14
73 / 100
190 ms262144 KiB
#include "bits/stdc++.h" using namespace std; #define int long long signed main () { int W, n; cin >> W >> n; vector <int> v, w; for(int i = 0; i < n; i ++) { int V, WW; cin >> V >> WW; v.push_back(V); w.push_back(WW); int k; cin >> k; k = min(k , W/WW); k--; while(k --) { v.push_back(V); w.push_back(WW); } } vector <int> dp(W+1, -1e9); dp[0] = 0; for(int i = 0; i < v.size(); i ++) { for(int j = W; j >= 0; j --) { if(j-w[i] >= 0) dp[j] = max(dp[j], dp[j-w[i]]+v[i]); } } cout << *max_element(dp.begin(), dp.end()); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:25:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i = 0; i < v.size(); 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...