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>
typedef long long int ll;
#define INF ll(1e9 + 7)
#define N (ll)2e2 + 5
using namespace std;
void solve(){
ll s, n, g,t, t2;
bool bb=0;
cin >> s >> n;
ll v[n+1], w[n+1], k[n+1], dp[n+2][s+2];
memset(dp, 0, sizeof(dp));
for(int i=1; i<=n; i++){
cin >> v[i] >> w[i] >> k[i];
}
for(int i=1; i<=n; i++){
t=0;
t2 = -1;
for(int j=1; j<=s; j++){
dp[i][j] = dp[i-1][j];
g = j-w[i];
if(g>=0 && ((dp[i][g] + v[i]) > max(dp[i][j], dp[i-1][g] + v[i]))){
if(dp[i][g] != t2)++t;
if(t <= k[i]){
dp[i][j] = dp[i][g] + v[i];
t2=dp[i][g];
bb=1;
}
}
else{
t= 0;
}
if(g>=0 && !bb){
if(dp[i-1][g] + v[i] > max(dp[i][g], dp[i][j]))t=1;
dp[i][j] = max(dp[i][g], max(dp[i-1][g] + v[i], dp[i][j]));
}
bb=0;
}
}
cout<<dp[n][s];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
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... |