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;
#define int long long
void solve(){
int s,n; cin>>s>>n;
vector<vector<int>>arr(n,vector<int>(3,0));
for(int i=0; i<n;i++){
int v,w,k; cin>>v>>w>>k;
arr[i][0] = v ;
arr[i][1] = w ;
arr[i][2] = k ;
}
vector<int>dp(s+1,0);
for(int i=0;i<n;i++){
for(int k =0;k<arr[i][2];k++){
if((k+1)*arr[i][1]>s) break;
for(int j=s;j>=arr[i][1];j--){
dp[j] = max( dp[j],dp[j-arr[i][1]]+arr[i][0]);
}
}
}
cout<<dp[s]<<endl;
}
int32_t main(){
int t=1; //cin>>t;
while(t--) solve();
}
# | 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... |