This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
#define FUL(i, a, N) for(int i = a; i < N; i++)
#define FUE(i, a, N) for(int i = a; i <= N; i++)
int S, N, ind, inow, iprev;
pair<int, pair<int, int>> kue[100002];
pair<int, int> kuenow[100002];
int dp[2][2002];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> S >> N;
FUE(i, 1, N){
cin >> kue[i].fi >> kue[i].se.fi >> kue[i].se.se;
}
if(N == 1){
cout << min(S / kue[1].se.fi, kue[1].se.se) * kue[1].fi;
}else{
FUE(i, 1, N){
while(kue[i].se.se--){
ind++;
kuenow[ind].fi = kue[i].fi;
kuenow[ind].se = kue[i].se.fi;
}
}
FUE(i, 1, ind){
inow = i % 2;
iprev = 1 - inow;
FUE(j, 1, S){
dp[inow][j] = dp[iprev][j];
if(j >= kuenow[i].se){
dp[inow][j] = max(dp[inow][j], dp[iprev][j - kuenow[i].se] + kuenow[i].fi);
}
}
}
cout << dp[ind % 2][S];
}
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... |