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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//ifstream cin("input.in");
//ofstream cout("output.out");
#define mod 1000000007
struct item {
long long v, w, k;
};
bool comp(item a, item b) {
if (a.w != b.w) return (a.w < b.w);
if (a.v != b.v) return (a.v < b.v);
return a.k < b.k;
}
long long dp[4005],Max;
long long s, n;
item a[100005];
int main() {
cin >> s >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].v >> a[i].w >> a[i].k;
a[i].k = min(a[i].k, s / a[i].w);
}
for (int i = 1; i <= n; i++) {
if (a[i].w != a[i - 1].w)
for (int l = 1; l <= a[i].k; l++)
for (int j = s; j >= a[i].w; j--) dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
else for (int l = a[i - 1].k; l <= a[i].k; l++)
for (int j = s; j >= a[i].w; j--) dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
for (int i = 1; i <= s; i++) Max = max(Max, dp[i]);
cout << Max;
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... |