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;
bool used[N];
void dfs(int x, vector<int> v[]){
used[x]=1;
for(auto u: v[x]){
if(!used[u])dfs(u, v);
}
}
void solve(){
ll s, n, g,t;
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;
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]))){
t++;
if(t <= k[i])dp[i][j] = dp[i][g] + v[i];
}
else{
t= 0;
}
if(g>=0)dp[i][j] = max(dp[i-1][g] + v[i], dp[i][j]);
}
}
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... |