Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,Gmax;
- struct obiect
- {
- int g,v;
- };
- obiect a[10001];
- void Citire()
- {
- int i;
- cin>>n>>Gmax;
- for(i=1;i<=n;i++) cin>>a[i].g>>a[i].v;
- }
- bool comp(obiect A,obiect B)
- {
- return(A.v*B.g>A.g*B.v);
- }
- void Greedy()
- {
- int i;
- double CostMax=0;
- sort(a+1,a+n+1,comp);
- for(i=1;i<=n and Gmax>=a[i].g;i++)
- {
- Gmax-=a[i].g;
- CostMax+=a[i].v;
- }
- if(i<=n and Gmax>0)
- CostMax+=(double)(Gmax*a[i].v)/a[i].g;
- cout<<CostMax<<endl;
- }
- int main()
- {
- Citire();
- Greedy();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement