Submission #928969

#TimeUsernameProblemLanguageResultExecution timeMemory
928969THXuanKnapsack (NOI18_knapsack)C++14
100 / 100
81 ms36704 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #define INF 1e9 using namespace std; typedef long long ll; vector<ll>sum[2005]; ll dp[2005][2005]; void solve() { ll s, n; cin >> s >> n; vector<pair<ll, pair<ll, ll>>>a; for (int i = 1; i <= n; i++) { ll v, w, k; cin >> v >> w >> k; a.push_back({ v, {w, k} }); } sort(a.rbegin(), a.rend()); for (int i = 1; i <= s; i++) sum[i].push_back(0); for (int i = 0; i < n; i++) { ll v = a[i].first; ll w = a[i].second.first; ll k = a[i].second.second; int sz = sum[w].size(); if (sz >= (s / w) + 1) continue; for (int j = sz; j < min(sz + k, (s / w) + 1); j++) { sum[w].push_back(sum[w][j - 1] + v); } } for (int i = 1; i <= s; i++) { for (int j = 0; j <= s; j++) { for (int k = 0; k < sum[i].size(); k++) { if (j - (k * i) >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - (k * i)] + sum[i][k]); } } } cout << dp[s][s] << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin>>t; while (t--) solve(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    for (int k = 0; k < sum[i].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...