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 <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <utility>
using namespace std;
#define fast_io ios::sync_with_stdio(0), cin.tie(0)
#define pb push_back
#define sz(x) (int)x.size()
#define rng(x) begin(x), end(x)
#define fst first
#define snd second
template <typename T>
using vt = vector<T>;
using vi = vt<int>;
using pi = pair<int, int>;
using vp = vt<pi>;
const int N = 2e3+7;
int dp[N]; vp wt[N]; vp fin;
void solve() {
int s, n; cin >> s >> n;
for(int i = 0; i < n; i++) {
int v, w, c; cin >> v >> w >> c;
wt[w].pb({v, c});
}
for(int i = 1; i <= s; i++) sort(rng(wt[i]), greater<pi>());
memset(dp, 0xff, sizeof(dp)); dp[0] = 0;
int ret = 0;
for(int w = 1; w <= s; w++) {
if(!sz(wt[w])) continue;
int l = sz(wt[w]), p = 0, cp = 0, m = 0; auto [cv, cc] = wt[w][p];
while(p < l && m <= s) {
for(int j = s, k = s-w; ~k; j--, k--) {
if(~dp[k]) dp[j] = max(dp[j], dp[k]+cv), ret = max(ret, dp[j]);
}
cp++, m += w;
if(cp >= cc) {
p++, cp = 0;
if(p < l) cv = wt[w][p].fst, cc = wt[w][p].snd;
}
}
}
cout << ret << "\n";
}
int main() {
fast_io;
solve();
}
# | 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... |