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
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;
const int maxn = 2010;
const int INF = LLONG_MAX/2;
const int mod = 1e9+7;
int S, n;
vector <pi> items[maxn];
int dp[maxn];
void tryitem(int w, int v) {
for (int i = S; i - w >= 0;i--) {
dp[i] = max(dp[i], dp[i-w] + v);
}
}
int32_t main() {
FAST
cin >> S >> n;
for (int i =0;i<n;i++) {
int v,w,k; cin >> v >> w >> k;
items[w].push_back(pi(v,k));
}
for (int i =1;i<=S;i++) {
sort(all(items[i]));
}
for (int i =1;i<=S;i++) {
int co = 0;
for (auto [v, k] : items[i]) {
for (int j = 0;j<k;j++) {
tryitem(i, v);
co++;
if (co * i > S) goto dd;
}
}
dd:;
}
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... |