Submission #752275

#TimeUsernameProblemLanguageResultExecution timeMemory
752275phongcdKnapsack (NOI18_knapsack)C++14
100 / 100
56 ms3788 KiB
#include <bits/stdc++.h> #define ll long long #define ii pair <int, int> #define ill pair <ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define file "test" using namespace std; const int N = 2e3 + 5; const int MOD = 1e9 + 7; const ll INF = 1e18; const int base = 311; const int BLOCK_SIZE = 2000; int n, m; ll f[N]; vector <ii> g[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> m >> n; for (int i = 1; i <= n; i ++) { int v, w, k; cin >> v >> w >> k; g[w].push_back({v, k}); } for (int i = 1; i <= m; i ++) { if (g[i].empty()) continue; sort(all(g[i]), greater <ii> ()); int id = 0; for (int j = 1; i * j <= m; j ++) { if (id >= g[i].size()) break; for (int k = m; k >= i; k --) f[k] = max(f[k], f[k - i] + g[i][id].fi); if (-- g[i][id].se == 0) id ++; } } cout << f[m]; } /* /\_/\ zzZ (= -_-) / >u >u */

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             if (id >= g[i].size()) break;
      |                 ~~~^~~~~~~~~~~~~~
#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...