이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define pi pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxN = 1e5+5;
const int maxV = 2e3+5;
int cnt = 0;
pi item[maxN*30]; //.fi = value; .se = weight;
int f[maxV];
int S,N;
bool cmp(pi a, pi b){
return a.se < b.se;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("../test.in","r",stdin);
cin >> S >> N;
for(int i = 1; i <= N; ++i){
int v,w,k; cin >> v >> w >> k;
for(int j = 1; j <= k; j <<= 1){
if(w * j > S)break;
item[++cnt] = pi(v*j,w*j);
k -= j;
}
if(k > 0 && w * k <= S)item[++cnt] = pi(v*k,w*k);
}
sort(item+1,item+cnt+1,cmp);
for(int i = 1; i <= cnt; ++i){
if(item[i].se > S)break;
for(int j = S; j >= item[i].se; --j){
if(f[j-item[i].se] + item[i].fi > f[j])
f[j] = f[j-item[i].se] + item[i].fi;
}
}
cout << f[S] << '\n';
}
# | 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... |