Submission #797862

#TimeUsernameProblemLanguageResultExecution timeMemory
797862OrazBKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms340 KiB
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second

const int N = 1e5+5;
int dp[N], cur[N];

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int S, n;
	cin >> S >> n;
	for (int i = 1; i <= n; i++){
		int v, w, k;
		cin >> v >> w >> k;
		for (int j = 0; j <= S-w; j++){
			if ((!j or dp[j]) and cur[j] < k and dp[j+w] < dp[j]+v){
				dp[j+w] = dp[j]+v;
				cur[j+w] = cur[j]+1; 				
			}
		}
		for (int j = 0; j <= S; j++) cur[j] = 0;
	}
	cout << *max_element(dp+1,dp+S+1);
}	
#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...