Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include<algorithm>
  4. #include<string.h>
  5. #pragma warning (disable:4996)
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12. int q1, p1, q2, p2, a, sum = 0;
  13. double profit1, profit2;
  14. cin >> q1 >> p1 >> q2 >> p2 >> a;
  15. profit1 = p1 / q1;
  16. profit2 = p2 / q2;
  17.  
  18. while (true)
  19. {
  20. if (a <= 0)
  21. {
  22. cout << sum;
  23. return 0;
  24. }
  25. if (profit2 < profit1)
  26. {
  27. if (abs(a - q1) > abs(a - q2))
  28. {
  29. a = a - q2;
  30. sum = sum + p2;
  31. }
  32. else
  33. {
  34. a = a - q1;
  35. sum = sum + p1;
  36. }
  37. }
  38. else
  39. {
  40. a = a - q1;
  41. sum = sum + p1;
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement