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 pair<int, int> pi;
typedef vector<int> vi;
const int NN = 1e6+3;
int n, S, used[2003];
ll dp[2003];
int main()
{
//setIO("");
cin >> S >> n;
int V, W, K;
for(int j=0;j<n;j++){
cin >> V >> W >> K;
memset(used, 0, sizeof(used));
for(int i=1;i<=S;i++){
if(i-W >= 0 && dp[i-W] + V > dp[i] && used[i-W] <= K-1){
used[i] = used[i-W] + 1;
dp[i] = dp[i-W] + V;
}
}
}
ll ans = 0;
for(int i=0;i<=S;i++){ans = max(ans, dp[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... |