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;
vector<pair<int, int>> items[2005];
long long dp[2005];
int main(){
long long s;
int n;
cin >> s >> n;
for(int i = 1; i <= n; i++){
int v, w, k;
cin >> v >> w >> k;
items[w].push_back({v, k});
}
for(int i = 1; i <= s; i++){
sort(items[i].rbegin(), items[i].rend());
long long curr = 0;//, curr_v = 0;
for(const auto &[v, k] : items[i]){
if(curr > s) break;
for(int j = 1; j <= k && curr <= s; j++){
curr += i;
// curr_v += v;
for(int w = s; w >= curr; w--) dp[w] = max(dp[w], dp[w - i] + v);
}
}
}
cout << dp[s];
}
# | 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... |