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 MAXX = 1e5 + 5;
int s,n,dp[2001][MAXX];
struct Product{
int v,w,k;
};
Product product[MAXX];
bool cmp(Product a, Product b){
return a.w < b.w;
}
int main(){
cin >> s >> n;
for (int i = 0; i < n; i++) cin >> product[i].v >> product[i].w >> product[i].k;
sort(product,product + n,cmp);
for (int i = 1; i <= s; i++){
for (int j = 0; j < n; j++){
if (i >= product[j].w){
int num = 1;
while (num*product[j].w <= i && num <= product[j].k){
dp[i][j] = max(max(dp[i - num*product[j].w][j - 1] + product[j].v*num,dp[i][j]),max(dp[i - 1][j],dp[i][j - 1]));
num++;
}
}
}
}
cout << dp[s][n - 1];
return 0;
}
# | 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... |