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;
long long v[100005],w[100005],k[100005];
long long dp[100005][2005],ans;
int main() {
long long s,n;
cin >> s >> n;
for (int i=1;i<=n;i++) cin >> v[i] >> w[i] >> k[i];
for (int i=1;i<=n;i++) {
for (int j=0;j<=s;j++) {
dp[i][j] = max(dp[i][j],dp[i-1][j]);
long long num = min(k[i],(s-j)/w[i]);
dp[i][j+num*w[i]] = max(dp[i][j+num*w[i]],dp[i-1][j]+v[i]*num);
}
}
for (int i=0;i<=s;i++) ans = max(ans,dp[n][i]);
cout << ans << endl;
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... |