Submission #1053978

#TimeUsernameProblemLanguageResultExecution timeMemory
1053978ssitaramKnapsack (NOI18_knapsack)C++17
73 / 100
1096 ms2816 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct item { ll v, w, k; }; int main() { ios::sync_with_stdio(0); cin.tie(nullptr); ll s, n; cin >> s >> n; vector<item> v(n); for (ll i = 0; i < n; ++i) { cin >> v[i].v >> v[i].w >> v[i].k; } vector<ll> best(s + 1), valof(s + 1); for (ll i = 0; i < n; ++i) { vector<set<tuple<ll, ll, ll>>> prevs(v[i].w); ll last = 3001; for (ll j = 0; j <= s; ++j) { if (!(j % v[i].w)) --last; valof[j] = best[j] + v[i].v * last; prevs[j % v[i].w].insert({valof[j], j, best[j]}); if (prevs[j % v[i].w].size() == v[i].k + 2) { ll idx = j - v[i].w * (v[i].k + 1); auto it = prevs[j % v[i].w].lower_bound({valof[idx], idx, 0}); prevs[j % v[i].w].erase(it); } auto it = prev(prevs[j % v[i].w].end()); best[j] = get<2>(*it) + (j - get<1>(*it)) / v[i].w * v[i].v; } } cout << best.back() << '\n'; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:26:33: warning: comparison of integer expressions of different signedness: 'std::set<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   26 |    if (prevs[j % v[i].w].size() == v[i].k + 2) {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
#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...