# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
899964 | KN200711 | Knapsack (NOI18_knapsack) | C++14 | 48 ms | 3676 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 ld long double
# define fi first
# define se second
# define pll pair<ll, ll>
# define pdd pair<ld, ld>
# define pii pair<int, int>
using namespace std;
vector<pii> V[2001];
ll dp[2001];
int main() {
int S, N;
scanf("%d %d", &S, &N);
for(int i=1;i<=N;i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
V[b].push_back({a, c});
}
for(int i=1;i<=S;i++) {
sort(V[i].begin(), V[i].end());
int cnt = 0;
while(V[i].size() && cnt <= S / i) {
pii G = V[i].back();
V[i].back().se--;
if(V[i].back().se == 0) V[i].pop_back();
for(int d=S;d>=i;d--) {
dp[d] = max(dp[d], dp[d - i] + G.fi);
}
cnt++;
}
}
ll ans = 0ll;
for(int i=0;i<=S;i++) ans = max(ans, dp[i]);
printf("%lld\n", ans);
return 0;
}
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... |