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 n, m;
ll a[mxN], b[mxN], c[mxN];
ll dp[mxN][10005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |