# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1195956 | osheesh | Knapsack (NOI18_knapsack) | C++20 | 1096 ms | 440 KiB |
#include <bits/stdc++.h>
#define en '\n'
#define sp ' '
#define ll long long
#define pii pair<int, int>
#define piii pair<int, pair<int, int>>
#define maxx(a,b) a=max(a,b)
#define minn(a,b) a=min(a,b)
#define st first
#define nd second
using namespace std;
const int N=1e5+5;
ll dp[2005];
// int v[N],w[N],k[N];
int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int wei,n,v,w,k;
scanf("%d%d",&wei,&n);
// for(int i=1;i<=n;i++) cin>>v[i]>>w[i]>>k[i];
for(int i=1;i<=n;i++){
scanf("%d%d%d",&v,&w,&k);
// int tmp=min(k[i],wei/w[i]);
int tmp=min(k,wei/w);
for(int j=1;tmp;j<<=1){
int cnt=min(j,tmp);
ll nv=1LL*v*cnt,nw=1LL*w*cnt;
for(int curr=wei;curr>=nw;curr--) maxx(dp[curr],dp[curr-nw]+nv);
tmp-=cnt;
}
}
printf("%lld",dp[wei]);
return 0;
}
컴파일 시 표준 에러 (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... |