Submission #813094

#TimeUsernameProblemLanguageResultExecution timeMemory
813094AliVuKnapsack (NOI18_knapsack)C++17
73 / 100
1084 ms17784 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define el '\n' const int maxn = 2e3 + 3, N = 1e5 + 5; int dp[2][maxn]; vector<pair<int, int>> a; void Solve() { int S, n; cin >> S >> n; for(int i = 1; i <= n; i++) { int v, w, k; cin >> v >> w >> k; int p = 1; while(p < k) { a.push_back({v * p, w * p}); k -= p; p <<= 1; } if(k) a.push_back({v * k, w * k}); } for(int i = 0; i < 2; i++) for(int j = 0; j < maxn; j++) { dp[i][j] = -1; if(j == 0) dp[i][j] = 0; } for(int k = 0; k < a.size(); k++) { int i = k % 2; for(int j = 0; j < maxn; j++) { if(dp[i][j] != -1 && j + a[k].second < maxn) dp[1 - i][j + a[k].second] = max(dp[1 - i][j + a[k].second], dp[i][j] + a[k].first); dp[1 - i][j] = max(dp[1 - i][j], dp[i][j]); } } int ans = 0; for(int i = 1; i <= S; i++) { ans = max({ans, dp[0][i], dp[1][i]}); } cout << ans; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0); int t = 1;// cin >> t; while(t--) Solve(); }

Compilation message (stderr)

knapsack.cpp: In function 'void Solve()':
knapsack.cpp:26:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int k = 0; k < a.size(); k++) {
      |                    ~~^~~~~~~~~~
#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...