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 endl '\n'
#define inf32 ((int)1e9 + 7)
#define inf64 ((long long)1e18 + 7)
#define MASK32(x) (1 << (x))
#define MASK64(x) (1LL << (x))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define all(a) begin(a), end(a)
#define isz(a) ((int)a.size())
const int N = 1e5 + 1, S = 2e3 + 1;
struct Item {
int v, w, k;
bool operator<(const Item& rhs) {
return v > rhs.v;
}
};
vector<Item> W[S];
int dp[S];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int s, n;
cin >> s >> n;
for(int i = 1, v, w, k; i <= n; ++i) {
cin >> v >> w >> k;
W[w].push_back({v, w, k});
}
vector<Item> v;
for(int i = 1; i <= s; ++i) {
int cnt = 0;
sort(all(W[i]));
for(const Item& it : W[i]) {
v.push_back({it.v, i, min((s - cnt) / i + 1, it.k)});
cnt += i * min((s - cnt) / i + 1, it.k);
if(cnt > s) break;
}
}
for(Item& it : v) {
for(int i = 1; i <= it.k; ++i)
for(int w = s; w >= it.w; --w) dp[w] = max(dp[w], dp[w - it.w] + it.v);
}
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... |