Submission #973813

#TimeUsernameProblemLanguageResultExecution timeMemory
973813pfkKnapsack (NOI18_knapsack)C++14
29 / 100
1 ms396 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...