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>
#define int long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5 + 5, MAX = 2e3 + 5, MOD = 1e9 + 7, INF = 1e18 + 5;;
int s, n, v[N], w[N], k[N], dp[N];
vector<pii> items[MAX];
vector<pii> fin;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s >> n;
for(int i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
items[w[i]].push_back({v[i], k[i]});
}
for(int i = 1; i <= s; i++){
sort(items[i].rbegin(), items[i].rend());
int needed = ((s + i - 1) / i);
for(pii item : items[i]){
int used = min(needed, item.second);
needed -= item.second;
int cnt = 1;
while(used >= cnt){
fin.push_back({i * cnt, item.first * cnt});
used -= cnt; cnt *= 2;
}
if(used) fin.push_back({i * used, item.first * used});
if(needed == 0) break;
}
}
for(int i = 0; i <= s; i++) dp[i] = -INF;
dp[0] = 0;
int sum = 0;
for(pii item : fin){
for(int i = min(sum, s - item.first); i >= 0; i--){
dp[i + item.first] = max(dp[i + item.first], dp[i] + item.second);
}
sum += item.first;
}
cout << *max_element(dp, dp + s + 1);
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... |