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;
#define ll long long
#define ar array
const int mxS=2000;
int n, s, dp[mxS+1];
vector<ar<int, 2>> v[mxS+1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> n;
for (int i=0; i<n; ++i) {
int a, b, c;
cin >> a >> b >> c;
v[b].push_back({a, c});
}
for (int i=1; i<=s; ++i) {
if (v[i].empty())
continue;
sort(v[i].rbegin(), v[i].rend());
int x=i;
for (ar<int, 2> a : v[i]) {
if (x>s)
break;
for (int j=0; j<a[1]&&x<=s; ++j, x+=i)
for (int k=s; k>=i; --k)
dp[k]=max(dp[k], dp[k-i]+a[0]);
}
}
cout << dp[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... |