이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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] && dp[j] < 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... |