Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iomanip>
  4. using namespace std;
  5. struct rucsac{int c,g;};
  6. rucsac a[10000];
  7. bool cmp(rucsac a,rucsac b)
  8. {
  9. if(a.c*b.g>b.c*a.g)return true;
  10. else return false;
  11. }
  12. int main()
  13. {int n,k,i,greut;
  14. float cost;
  15. cin>>n>>k;
  16. for(i=1;i<=n;i++)
  17. cin>>a[i].g>>a[i].c;
  18. sort(a+1,a+n+1,cmp);
  19. cost=greut=0;
  20. i=1;
  21. while(greut+a[i].g<=k)
  22. {
  23. greut=greut+a[i].g;
  24. cost=cost+a[i].c;
  25. i++;
  26. }
  27. k=k-greut;
  28. cost=cost+k*a[i].c*1.0/a[i].g;
  29. cout<<fixed<<setprecision(2)<<cost;
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement