Submission #772107

#TimeUsernameProblemLanguageResultExecution timeMemory
772107asdf334Knapsack (NOI18_knapsack)C++17
73 / 100
1083 ms1320 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[2005];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	for (ll& i : dp) i = -1;
	dp[0] = 0;
	ll S, N; cin >> S >> N;
	for (int i = 0; i < N; ++i) {
		ll v, w, k; 
		cin >> v >> w >> k;
		for (ll i = 2004; i >= 0; --i) {
			if (dp[i] >= 0) {
				ll c = 1; ll j = c * w + i;
				while (j <= S && c <= k) {
					dp[j] = max(dp[j], dp[i] + c * v);
					++c; j += w;
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i <= S; ++i) {
		ans = max(ans, dp[i]);
	}
	cout << ans << '\n';
}
#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...