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>
typedef long long ll;
using namespace std;
int main()
{
ll S, N;
cin >> S >> N;
vector<ll> vs(N + 1, 0);
vector<ll> ws(N + 1, 0);
vector<ll> ks(N + 1, 0);
for(int i = 1; i <= N; i++){
ll V;
ll W;
ll K;
cin >> V >> W >> K;
vs[i] = V;
ws[i] = W;
ks[i] = K;
}
vector<vector<ll>> dp(S + 1, vector<ll>(N + 1, 0));
for(int s = 1; s <= S; s++){
for(int i = 1; i <= N; i++){
for(int k = 1; k <= ks[i]; k++){
if(s >= (k * ws[i])){
dp[s][i] = max(dp[s][i], dp[s-(ws[i]*k)][i-1] + (vs[i]*k)) ;
}else{
break;
}
}
dp[s][i] = max(dp[s][i], dp[s][i-1]);
}
}
cout << dp[S][N];
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... |