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 N 300005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
ll T, n, s, v[N], w[N], k[N], dp[N], a[N];
vector <pair<ll,ll>> v1;
int main(){
cin >> s >> n;
for(int i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= s; j++){
if(dp[j] != 0 or j == 0){
if(a[j] + 1 <= k[i]){
if(dp[j] + v[i] > dp[j + w[i]]){
dp[j + w[i]] = (dp[j] + v[i]);
a[j + w[i]] = a[j] + 1;
}
}
}
}
for(int j = 0; j <= s; j++) a[j] = 0;
}
ll ans = 0;
for(int i = 0; i <= s; i++){
ans = max(ans,dp[i]);
}
cout << ans;
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... |