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>
#define int long long
using namespace std;
int n,s,V[1000001], W[1000001], K[1000001], dp[2][2010];
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> s >> n;
for(int i = 1; i<=n; ++i) cin >> V[i] >> W[i] >> K[i];
for(int i = 1; i<=n; ++i){
int cur = i&1, pre = cur^1;
for(int j = 0; j<=s; ++j){
dp[cur][j] = dp[pre][j];
for(int k = 1; k<=K[i]; ++k){
if(j - W[i]*k < 0) break;
dp[cur][j] = max(dp[cur][j], dp[pre][j - W[i]*k] + V[i]*k);
}
}
}
cout << dp[n&1][s];
}
# | 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... |