이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 110;
const int MAXK = 2010;
const int LOG = 20;
const int MOD = 1e9+7;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
int n, s;
int v[MAXN], w[MAXN], k[MAXN];
pii dp[MAXN][MAXK];
vector <ipii> vec;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> s >> n;
for(int i=1; i<=n; i++){
cin >> v[i] >> w[i] >> k[i];
vec.pb({w[i], {v[i], k[i]}});
}
vec.pb({INF, {INF, INF}});
sort(vec.rbegin(), vec.rend()); // sort max
for(int j=1; j<=s; j++) dp[0][j] = {-INF, 0};
for(int i=1; i<=n; i++){
ipii tp = vec[i];
//cout << tp.fi << ' ' << tp.se.fi << ' ' << tp.se.se << " p\n";
for(int j=0; j<=s; j++){ // max value kalo udh di i, isinya j
dp[i][j] = dp[i-1][j];
}
for(int j=0; j<=s; j++){
for(int ba=1; ba<=tp.se.se; ba++){ // based on weight
int wei = ba*tp.fi;
if(j-wei < 0) break;
int nw = dp[i-1][j-wei].fi + ba * tp.se.fi;
if(dp[i][j].fi < nw){
dp[i][j].fi = nw;
dp[i][j].se = ba;
//cout << i << ' ' << j << ' ' << nw << ' ' << ba << " pp\n";
}
}
}
}
int mx = -INF;
for(int i=0; i<=s; i++) mx = max(mx, dp[n][i].fi);
cout << mx << '\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... |