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;
using ll = long long;
void solve(){
int s, n; cin >> s >> n;
vector<int> W, V;
ll v, w, r;
if(n==1){
cin >> v >> w >> r;
cout << min(s/w, r) * v << '\n';
return;
}
for(int i = 0; i<n; i++){
cin >> v >> w >> r;
while(r--){
W.push_back(w);
V.push_back(v);
}
}
n = W.size();
int a[s+1]{};
fill(a, a+s+1, -1e9);
a[0] = 0;
for(int i = 0; i<n; i++){
for(int j = s; j>=W[i]; j--){
a[j] = max(a[j], a[j-W[i]] + V[i]);
}
}
int best = 0;
for(int i = 0; i<=s; i++) best = max(best, a[i]);
cout << best << '\n';
}
signed main()
{
// #ifndef LOCAL
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// #endif
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... |