# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703292 | pahn | Knapsack (NOI18_knapsack) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e3+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][10005];
void solve() {
cin >> m >> n;
for (int i = 1; i <= n; ++i) cin >> b[i] >> a[i] >> c[i];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
for (int z = 0; z <= c[i]; ++z){
if (z*a[i] <= j) dp[i][j] = max(dp[i][j], dp[i-1][j - z*a[i]] + b[i]*z);
}
}
}
cout << dp[n][m];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
// cin >> t;
t = 1;
while(t--) {
solve();
}
return 0;
}