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 int long long
#define fi first
#define se second
#define ll long long
#define pb push_back
const int N = 2005;
int s, n;
ll dp[N];
vector<pair<int, int>> item[N];
void input() {
cin >> s >> n;
for (int i = 1; i <= n; ++i) {
int v, w, k;
cin >> v >> w >> k;
item[w].pb({v, k});
}
}
void solve() {
for (int i = 1; i <= s; ++i) {
dp[i] = -1e18;
}
for (int i = 1; i <= 2000; ++i) {
sort(item[i].begin(), item[i].end(), greater<pair<int, int>>());
int val = 0;
for (auto it : item[i]) {
int sl = 0;
while (sl < it.se && val <= s) {
val += i;
++sl;
for (int j = s; j >= i; --j) {
dp[j] = max(dp[j], dp[j - i] + it.fi);
}
}
if (val > s) break;
}
}
ll ans = 0;
for (int i = 1; i <= s; ++i) {
ans = max(ans, dp[i]);
}
cout << ans;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
input();
solve();
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... |