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 F first
#define S second
#define PB push_back
using namespace std;
using ll = long long;
void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
const int MXN = 1e5+5;
int s, n;
ll W[MXN], V[MXN], K[MXN];
ll dp[MXN];
vector<pair<ll, ll>> best[MXN];
int main() {
FASTIO();
cin >> s >> n;
for(int i = 0; i < n; i++) {
cin >> V[i] >> W[i] >> K[i];
K[i] = min(K[i], (ll)s);
best[W[i]].PB({V[i], K[i]});
}
for(int i = 1; i <= s; i++) {
sort(best[i].begin(), best[i].end());
int k = 0;
for(auto p : best[i]) {
for(int j = 0; j < p.S; j++) {
if(i*k > s) break;
for(int u = s; u >= i; u--) {
dp[u] = max(dp[u], dp[u-i]+p.F);
}
k++;
}
}
}
cout << *max_element(dp, dp+s+1) << "\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... |