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 ll long long
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int s, n; cin >> s >> n;
vector<int> v(n), w(n), k(n);
map<int, vector<pair<int,int>>> wghts;
for (int i = 0; i < n; ++i) {
cin >> v[i] >> w[i] >> k[i];
wghts[w[i]].push_back({v[i], k[i]});
}
vector<ll> dp(s+1);
for (int i = 0; i< n; ++i) {
for (int j = s; j >= w[i]; --j) {
for (int t = 0; t <= k[i]; ++t) {
if (j >= w[i] * t) {
dp[j] = max(dp[j], dp[j - w[i] * t] + v[i] * t);
}
}
}
}
cout << dp[s] << "\n";
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... |