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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
int n, s;
cin>>s>>n;
vector<vector<ll>>dp(2, vector<ll>(s+1, 0));
for (int i=0; i<n; i++){
int v, w, k;
cin>>v>>w>>k;
int kini=k;
for (int j=1; j<s+1; j++){
if (j>=w and k>0){
if (dp[0][j]<dp[1][j-w]+v){
k--;
dp[1][j]=dp[1][j-w]+v;
}else dp[1][j]=max(dp[0][j], dp[1][j-1]);
if (dp[1][j]==dp[0][j]) k=kini;
}else if (j>=w){
dp[1][j]=max(dp[0][j-w]+v, max(dp[0][j], dp[1][j-1]));
if (dp[1][j]==dp[0][j]) k=kini;
else if (dp[1][j]==dp[0][j-w]+v) k=kini-1;
}else dp[1][j]=dp[0][j];
}swap(dp[0], dp[1]);
}cout<<dp[0][s]<<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... |