Advertisement
Malinovsky239

Untitled

Nov 9th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cstring>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. #define y1 Y1
  11.  
  12. typedef long long LL;
  13.  
  14. int main() {
  15.     LL t1, t2, x1, x2, t0, ans1, ans2, opt;
  16.  
  17.     while (cin >> t1 >> t2 >> x1 >> x2 >> t0) {
  18.         opt = LL(1e18);
  19.  
  20.         for (int y2 = 0; y2 <= x2; y2++) {
  21.             LL sum = y2 * (t2 - t0);                   
  22.             int y1;
  23.  
  24.             if (t0 != t1)
  25.                 y1 = sum / (t0 - t1);
  26.             else
  27.                 y1 = x1;
  28.  
  29.             if (y1 > x1) y1 = x1;
  30.  
  31.             sum += y1 * (t1 - t0);
  32.  
  33.             if ( (sum * (ans1 + ans2) < opt * (y1 + y2) || (sum * (ans1 + ans2) == opt * (y1 + y2) && y1 + y2 > ans1 + ans2)) && y1 + y2) {
  34.                 opt = sum;
  35.                 ans1 = y1;
  36.                 ans2 = y2;
  37.             }
  38.         }
  39.  
  40.         cout << ans1 << " " << ans2 << endl;
  41.  
  42.     }
  43.  
  44.     return 0;
  45. }
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement