# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752275 | phongcd | Knapsack (NOI18_knapsack) | C++14 | 56 ms | 3788 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |