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<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
ll knapsack(vector<pair<int,int>>arr,int s){ // (weight, reward)
vector<vector<ll>>dp(arr.size()+1,vector<ll>(s+1)); // dp[i][j] = if we take first i elements, how much can we take with j space left
/*for(int i=1;i<=arr.size();i++){
for(int j=0;j<=s;j++){
dp[i][j]=dp[i-1][j];
if(j-arr[i-1].first>=0){
dp[i][j]=max(dp[i][j],dp[i-1][j-arr[i-1].first]+arr[i-1].second);
}
}
}*/
return dp[(int)arr.size()][s];
}
void solve(){
int s,n;
cin>>s>>n;
vector<pair<int,int>>arr;
for(int i=0;i<n;i++){
int w,r,c;
cin>>r>>w>>c;
while(c--){
arr.emplace_back(w,r);
}
}
cout<<knapsack(arr,s)<<"\n";
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
/*
15 5
4 12 1
2 1 1
10 4 1
1 1 1
2 2 1
20 3
5000 15 1
100 1 3
50 1 4
*/
# | 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... |