제출 #1315151

#제출 시각아이디문제언어결과실행 시간메모리
1315151JuanJLKnapsack (NOI18_knapsack)C++20
12 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define fst first #define snd second #define pb push_back #define SZ(x) (int)x.size() #define ALL(x) x.begin(),x.end() #define mset(a,v) memset(a,v,sizeof(a)) #define forn(i,a,b) for(int i = a; i<b; i++) #define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; typedef long long ll; int main(){ ll s,n; cin>>s>>n; vector<pair<double,ll>> best(n); vector<double> vv(n); vector<double> ww(n); vector<ll> kk(n); forn(i,0,n){ double v,w; ll k; cin>>v>>w>>k; best[i]={v/w,i}; vv[i]=v; ww[i]=w; kk[i]=k; } sort(ALL(best)); reverse(ALL(best)); ll ag = 0; ll aw = 0; for(auto i:best){ ll ind = i.snd; ll cnt = (ll)((s-aw)/ww[ind]); cnt=min(cnt,kk[ind]); aw+=cnt*ww[ind]; ag+=cnt*vv[ind]; } cout<<ag<<'\n'; return 0; }
#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...