제출 #807158

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
8071582023-08-04 14:16:09sirigithKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms212 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
int s,n; cin>>s>>n;
vector<vector<int>> items(n);
for (int i=0;i<n;i++){
int x,y,z; cin>>x>>y>>z;
items[i]={x,y,z};
}
vector<int> dp(s+1,-1);
dp[0]=0;
for (auto j: items){
vector<int> cnt(s+1,j[2]); //num remaining of this particular item, take max
for (int i=0; i<s; i++){
if (dp[i]!=-1 and cnt[i]>0 and (i+j[1]<=s)){
if ((dp[i+j[1]]==-1) or (dp[i+j[1]]<(dp[i]+j[0]))){
dp[i+j[1]]=dp[i]+j[0];
cnt[i+j[1]]=cnt[i]-1;
} else if (dp[i+j[1]]==dp[i]+j[0]){
cnt[i+j[1]]=max(cnt[i+j[1]],cnt[i]-1);
}
}
}
}
int ans=0;
for (auto i: dp){
ans=max(ans,i);
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...