#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 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... |