# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1193286 | dprto | Knapsack (NOI18_knapsack) | C++20 | 1093 ms | 1608 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define f(i,n) for(long long i=1;i<=n;i++)
#define fi first
#define se second
#define mll map<long long,long long>
#define sll set<long long>
const ll du=1e9+7;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int n,s;
cin>>s>>n;
int w[n+1],v[n+1],c[n+1];
vector<ll> dp(s+1,0);
for(int i=1;i<=n;i++){
cin>>v[i]>>w[i]>>c[i];
vector<pll> bag;
ll cur=1,rem=c[i];
while(rem>0){
if(cur<=rem){
rem-=cur;
bag.push_back({v[i]*cur,w[i]*cur});
cur*=2;
}
else break;
}
if(rem>0)
bag.push_back({v[i]*rem,w[i]*rem});
for(pll x:bag){
for(ll j=s;j>=x.se;j--){
dp[j]=max(dp[j],dp[j-x.se]+x.fi);
}
}
}
cout<<dp[s];
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |