Submission #703294

#TimeUsernameProblemLanguageResultExecution timeMemory
703294pahnKnapsack (NOI18_knapsack)C++14
0 / 100
1074 ms724 KiB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5+5;
const int M = 1e9+7;
using vi = vector<int>;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define el '\n'
ll s,n, a[mxN], b[mxN], c[mxN], dp[mxN][2005];
void solve() {
	cin >> s >> n;
	for (int i = 1; i <= n; ++i) cin >> b[i] >> a[i] >> c[i];
	for (int i = 1; i <= n; ++i) {
		for (int w = 1; w <= s; ++w) {
			for (int j = 0; j <= c[i]; ++j) {
				if (j*a[i] <= w) dp[i][w] = max(dp[i][w], dp[i][w - j*a[i]] + j * b[i]);
			}
		}
	}
	cout << dp[n][s];
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    // cin >> t;
    t = 1; 
    while(t--) {
    	solve();
    }
    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...