Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include<algorithm>
- #include<string.h>
- #pragma warning (disable:4996)
- using namespace std;
- int main()
- {
- int q1, p1, q2, p2, a, sum = 0;
- double profit1, profit2;
- cin >> q1 >> p1 >> q2 >> p2 >> a;
- profit1 = p1 / q1;
- profit2 = p2 / q2;
- while (true)
- {
- if (a <= 0)
- {
- cout << sum;
- return 0;
- }
- if (profit2 < profit1)
- {
- if (abs(a - q1) > abs(a - q2))
- {
- a = a - q2;
- sum = sum + p2;
- }
- else
- {
- a = a - q1;
- sum = sum + p1;
- }
- }
- else
- {
- a = a - q1;
- sum = sum + p1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement