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 all(x) x.begin(),x.end()
#define fi first
#define se second
#define int long long //tehlikeli
#define pb push_back
#define sp <<' '<<
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<bool> vb;
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a) for(int i=(a);i>=0;i--)
#define contp(a) for(auto el:a) {cout<<el.fi<<'-'<<el.se<<' ';}cout<<endl
#define cont(a) for(auto el:a) {cout<<el<<' ';}cout<<endl
const int MAXN=105;
const int MAXS=2005;
const int INF=1e13+3;
int dp [MAXS][MAXN];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,s;
cin>>s>>n;
vi v(n+1);
vi w(n+1);
vi k(n+1);
FOR(i,n){
cin>>v[i+1]>>w[i+1]>>k[i+1];
}
FORE(i,1,s+1){
FORE(j,1,n+1){
dp[i][j]=dp[i][j-1];
FORE(t,1,k[j]+1){
if(i-w[j]*t>=0){
dp[i][j]=max(dp[i][j],dp[i-w[j]*t][j-1]+v[j]*t);
}
}
}
}
cout<<dp[s][n]<<endl;
}
# | 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... |