Submission #942297

#TimeUsernameProblemLanguageResultExecution timeMemory
942297TrendBattlesKnapsack (NOI18_knapsack)C++14
100 / 100
101 ms5700 KiB
//https://oj.uz/problem/view/NOI18_knapsack #include <bits/stdc++.h> using namespace std; using lli = int64_t; const lli inf = 0x3f3f3f3f3f3f3f3f; void maximise(lli& x, lli y) { if (x < y) x = y; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, S; cin >> S >> n; vector <vector <int>> value(S + 1); for (int i = 1; i <= n; ++i) { int v, w, k; cin >> v >> w >> k; int pow_2 = 1; while (k >= pow_2) { if ((lli) w * pow_2 <= S) { value[w * pow_2].push_back(v * pow_2); } k -= pow_2; pow_2 <<= 1; } if (k > 0 and (lli) w * k <= S) { value[w * k].push_back(v * k); } } vector <lli> dp(S + 1); for (int i = 1; i <= S; ++i) { sort(value[i].begin(), value[i].end(), greater <int> ()); if (value[i].size() > S / i) { value[i].erase(value[i].begin() + S / i, value[i].end()); } for (int v : value[i]) { for (int j = S; j >= i; --j) { maximise(dp[j], dp[j - i] + v); } } } cout << dp[S]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:39:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |         if (value[i].size() > S / 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...