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>
using namespace std;
using ll = long long;
map<int, int> sum;
const int mxN = 2*1e5+10;
ll dp[mxN];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int s, n;
cin >> s >> n;
vector<array<ll, 3>> v;
for(int i = 0; i < n; i++) {
ll val, w, k;
cin >> val >> w >> k;
v.push_back({val, w, k});
}
sort(v.rbegin(), v.rend());
vector<array<ll, 2>> a;
for(auto it : v) {
ll val = it[0], w = it[1], k = it[2];
while(sum[w]+w <= s && k) {
sum[w] += w;
k--;
a.push_back({w, val});
}
}
for(auto it : a) {
for(int x = s; x >= 0; x--) {
if(x-it[0] >= 0) {
dp[x] = max(dp[x], dp[x-it[0]]+it[1]);
}
}
}
ll ans = 0;
for(int i = 1; i <= s; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
# | 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... |