Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct obiect
  4. {
  5. int nr,gr,c;
  6. float ef;
  7. }v[2000];
  8. int G,n;
  9. int main()
  10. {
  11. cin>>n>>G;
  12. for(int i=1;i<=n;i++)
  13. {
  14. v[i].nr=i;
  15. cin>>v[i].gr>>v[i].c;
  16. v[i].ef=(v[i].c*1.0)/v[i].gr;
  17. }
  18. for(int i=1;i<n;i++)
  19. for(int j=i+1;j<=n;j++)
  20. if(v[i].ef<v[j].ef)
  21. swap(v[i],v[j]);
  22. float C=0;
  23. int i=1;
  24. while(i<=n && G>0)
  25. {
  26. if(v[i].gr<=G)
  27. {
  28. C=C+v[i].c;
  29. G=G-v[i].gr;
  30. }
  31. else
  32. {
  33. C=C+v[i].c*((G*1.0)/v[i].gr);
  34. G=G-v[i].gr*((G*1.0)/v[i].gr);
  35. }
  36. i++;
  37. }
  38. cout<<C;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement