Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- struct rucsac{int c,g;};
- rucsac a[10000];
- bool cmp(rucsac a,rucsac b)
- {
- if(a.c*b.g>b.c*a.g)return true;
- else return false;
- }
- int main()
- {int n,k,i,greut;
- float cost;
- cin>>n>>k;
- for(i=1;i<=n;i++)
- cin>>a[i].g>>a[i].c;
- sort(a+1,a+n+1,cmp);
- cost=greut=0;
- i=1;
- while(greut+a[i].g<=k)
- {
- greut=greut+a[i].g;
- cost=cost+a[i].c;
- i++;
- }
- k=k-greut;
- cost=cost+k*a[i].c*1.0/a[i].g;
- cout<<fixed<<setprecision(2)<<cost;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement