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 int long long
#define pb push_back
using namespace std;
const int maxn = 1e5 + 10, maxs = 2e3 + 10;
int s, n, dp[maxs];
vector <pair <int, int>> item[maxn];
int32_t main (){
ios_base::sync_with_stdio(0);
cin >> s >> n;
for (int v, w, k, i = 0; i < n; i++)
cin >> v >> w >> k,
item[w].pb({v, k});
for (int i = 1; i <= s; i++){
sort(item[i].begin(), item[i].end(), greater<pair <int, int>>());
int w = 0;
for (auto [v, k] : item[i]){
while (w + i <= s && k){
k--;
w += i;
for (int j = s; j >= i; j--)
dp[j] = max(dp[j], dp[j - i] + v);
}
if (w + i > s) break;
}
}
cout << 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... |