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 minn = 1e9;
int main(){
cin >> s >> n;
for (int i = 0; i < n; i++){
cin >> product[i].v >> product[i].w >> product[i].k;
minn = min(product[i].w,minn);
}
sort(product,product + n,cmp);
for (int i = 1; i <= s; i += minn){
for (int j = 0; j < n; j++){
if (i >= product[j].w){
int num = 1;
dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
while (num*product[j].w <= i && num <= product[j].k){
dp[i][j] = max(dp[(i - num*product[j].w - 1)/minn*minn + 1][j - 1] + product[j].v*num,dp[i][j]);
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... |