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;
const int nmax = 1e6;
const int smax = 2e3;
int dp[smax+5][smax+5];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int s, n; cin >> s >> n;
vector<pair<int, int>> cost[smax+5];
for(int i=1; i<=n; i++) {
int v, w, k; cin >> v >> w >> k;
cost[w].emplace_back(v, k);
}
for(auto &i : cost) sort(i.begin(), i.end(), greater<pair<int, int>>());
for(int i=0; i<=s; i++) {
for(int j=1; j<=i; j++) {
int taken = 0, val = 0;
dp[i][j] = dp[i][j-1];
for(auto item : cost[j]) {
for(int ct=0; ct<item.second and (taken+1)*j<=i; ++ct) {
taken++;
val += item.first;
dp[i][j] = max(dp[i][j], dp[i-taken*j][min(j-1,i-taken*j)]+val);
}
}
}
}
cout << dp[s][s];
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... |