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];
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 j = 1; j <= k[i]; j++){
v1.push_back({v[i],w[i]});
}
}
for(auto j : v1){
ll va = j.ff, we = j.ss;
for(int i = s; i >= 0; i--){
if(dp[i] != 0 or i == 0){
dp[i + we] = max(dp[i + we], dp[i] + va);
}
}
}
ll ans = 0;
for(int i = 0; i <= s; i++){
ans = max(dp[i], ans);
}
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... |