Submission #841746

#TimeUsernameProblemLanguageResultExecution timeMemory
841746digiEnceladusKnapsack (NOI18_knapsack)C++17
73 / 100
1051 ms1628 KiB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 1e5, S = 2e3;
int n, s, k, V[N+1], W[N+1], K[N+1];
ll pre[S+1], cur[S+1];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);

	cin >> s >> n;
	for (int i = 1; i <= n; i++)
        cin >> V[i] >> W[i] >> K[i];

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= s; j++) {
            cur[j] = pre[j];
            if (j - W[i] >= 0)
                for (int x = 1; x <= min(j/W[i], K[i]); x++)
                    cur[j] = max(cur[j], pre[j - x*W[i]] + x*V[i]);
        }
        copy(cur+1, cur+1+s, pre+1);
    }

    cout << cur[s];

	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...