#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue
template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<vi>;
using vvi = V<vi>;
const int N = 100'000;
const int S = 2000+5;
ll dp[S];
V<pi> wts[S];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int s, n, v, w, k;
cin >> s >> n;
f0r(i, n) {
cin >> v >> w >> k;
if (w > s) continue;
wts[w].pb({v, k});
}
fnr(ss, 1, s+1) {
if (!wts[ss].size()) continue;
sort(all(wts[ss]), greater<pi>());
vl cst(s/ss+1);
for (int k = 1, i = 0; i < wts[ss].size(); ++i)
for (; k <= s/ss && wts[ss][i].S; ++k) cst[k] = cst[k-1] + wts[ss][i].F, wts[ss][i].S--;
for (int sn = s; sn >= ss; --sn)
for (int k = 1; k <= sn/ss; ++k) dp[sn] = max(dp[sn], dp[sn - k * ss] + cst[k]);
}
ctn(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... |