#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 1e5 + 5;
ll V[mn], W[mn], K[mn], dp[2020], used[2020];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int S, n; cin >> S >> n;
for (int i = 1; i <= n; i++) cin >> V[i] >> W[i] >> K[i];
vector<int> ord(n);
for (int i = 1; i <= n; i++) ord[i - 1] = i;
sort(all(ord), [&] (int a, int b) { return V[a] > V[b]; });
int t = 0, counter = 0;
for (int i : ord) {
for (int iter = 0; iter < K[i]; iter++) {
if (used[W[i]] * W[i] > S) break;
for (int j = S; j >= W[i]; j--)
dp[j] = max(dp[j], dp[j - W[i]] + V[i]);
used[W[i]]++;
}
}
cout << dp[S];
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... |