#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif
constexpr int N = 2001;
constexpr long long inf = 1e18;
vector<array<int, 2>> f[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int s, n;
cin >> s >> n;
for (int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
f[w].push_back({v, k});
}
vector<vector<long long>> dp(s + 1, vector<long long>(s + 1, 0));
for (int i = 1; i <= s; i++) {
sort(f[i].rbegin(), f[i].rend());
for (int j = 1; j <= s; j++) {
auto b = f[i];
dp[i][j] = dp[i - 1][j];
long long sum = 0;
int id = 0, taken = 0;
for (int k = 1; k * i <= j; k++) {
if (id == b.size()) break;
if (id < b.size() && taken == b[id][1]) {
k--;
id++;
taken = 0;
continue;
}
sum += b[id][0];
taken++;
dp[i][j] = max(dp[i][j], dp[i - 1][j - k * i] + sum);
}
}
}
cout << ranges::max(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... |