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;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int S, n;
cin >> S >> n;
vector<pair<long long, int>> v = {{0, 0}};
for(int i = 1;i <= n;++i){
int val, w, k;
cin >> val >> w >> k;
k = min(k, S / w);
for(int j = 0;(1 << j) <= k;++j){
v.push_back({(1LL << j) * val, (1 << j) * w});
k -= (1 << j);
}
if(k)v.push_back({1LL * k * val, k * w});
}
n = (int)v.size() - 1;
vector<long long> dp(S + 1, -1e18);
dp[0] = 0;
for(int i = 1;i <= n;++i){
for(int j = S;j >= 0;--j){
if(j - v[i].second >= 0)dp[j] = max(dp[j], dp[j - v[i].second] + v[i].first);
}
}
long long mx = 0;
for(int i = 0;i <= S;++i){
mx = max(mx, dp[i]);
}
cout << mx << '\n';
}
# | 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... |