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;
typedef long long int lli;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
lli s, n;
cin >> s >> n;
lli item[n+5][3];// V, W, K
for(lli i = 0; i < n; i++){
cin >> item[i][0] >> item[i][1] >> item[i][2];
}
lli dp[s+5];
for(lli i = 0; i <= s; i++) dp[i] = 0;
lli used[s+5];
for(lli i = 0; i < n; i++){
for(lli j = 0; j < item[i][1]; j++){
used[j] = 0;
}
for(lli j = item[i][1]; j <= s; j++){
//cout << j << " : " << used[j - item[i][1]] + 1 << " <= " << item[i][2] << " && " << dp[j] << " < " << dp[j-item[i][1]] << " + " << item[i][0] << "\n";
if(used[j - item[i][1]] + 1 <= item[i][2] && max(dp[j], dp[j-1]) < dp[j-item[i][1]] + item[i][0]){
used[j] = used[j - item[i][1]] + 1;
dp[j] = dp[j-item[i][1]] + item[i][0];
}
else{
if(dp[j] >= dp[j-1]){
used[j] = 0;
}
else{
dp[j] = dp[j-1];
used[j] = used[j-1];
}
}
}
/*for(lli j = 0; j <= s; j++){
cout << dp[j] << " ";
}
cout << "\n";*/
}
cout << dp[s];
}
# | 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... |