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 ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define file \
freopen("time.in", "r", stdin);\
freopen("time.out", "w", stdout)
#define OJudge(in,out) \
freopen(in, "r", stdin);\
freopen(out, "w", stdout)
#define FIn \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false)
const string IN = "input.txt";
const string OUT = "output.txt";
ll n,m,a,b,c;
int tc;
int dp[2010][100010];
ll dp_ans[2010];
int v[100100], w[100100], k[100100];
void solve(){
cin>>a>>n;
for (int i = 0; i<n; i++){
cin>>v[i]>>w[i]>>k[i];
}
ll rslt = 0;
for(int i = 1; i<= a; i++){
ll ans = 0;
int idx = -1;
for(int j = 0; j < n; j++){
if(i - w[j] >= 0 && dp[i - w[j]][j] < k[j] && dp_ans[i - w[j]] + v[j] > ans){
idx = j;
ans = dp_ans[i - w[j]] + v[j];
}
}
if (idx != -1) {
for (int j = 0; j < n; j++) {
dp[i][j] = dp[i - w[idx]][j];
}
dp[i][idx]++;
dp_ans[i] = ans;
rslt = max(rslt, ans);
}
}
cout<<rslt;
}
int main() {
FIn;
//file;
bool test = 0;
if (test)
cin>>tc;
else tc = 1;
for (int i = 1; i<=tc; i++){
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... |