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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int s, n;
cin >> s >> n;
vector<vector<pii>> a(s + 1);
for (int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
a[w].push_back({v, k});
}
for (int i = 0; i <= s; i++) {
sort(a[i].rbegin(), a[i].rend());
}
vector<vector<int>> dp(s + 1, vector<int>(s + 1, 0));
for (int i = 1; i <= s; i++) {
for (int j = 0; j <= s; j++) {
int curw = 0;
int curv = 0;
dp[i][j] = max(dp[i - 1][j], dp[i][j]);
for (auto &el: a[i]) {
for (int p = 0; p < el.second; p++) {
curw += i;
curv += el.first;
if (curw > j)break;
dp[i][j] = max(dp[i][j], dp[i - 1][j - curw] + curv);
}
if (curw > j)break;
}
}
}
int ans = 0;
for (int i = 0; i <= s; i++) {
ans = max(ans, dp[s][i]);
}
cout << ans << endl;
}
# | 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... |