Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #define e (double)(1e-7)
  3. using namespace std;
  4. int n, t[51], x[51], c, maxi;
  5. double a, b;
  6. int main ()
  7. {
  8. cin >> n;
  9. for(int i = 1; i <= n; i++)
  10. cin >> t[i];
  11. for(int i = 1; i <= n; i++)
  12. {
  13. cin >> x[i];
  14. maxi = max(maxi, x[i]);
  15. }
  16. cin >> c;
  17. b = (double)(maxi);
  18. while(b - a > e)
  19. {
  20. double orta = (a + b) / 2;
  21. //cout << a << " " << orta << " " << b << " || ";
  22. double sum = 0.0;
  23. bool ok = false;
  24. for(int i = 1; i <= n; i++)
  25. {
  26. for(int j = 1; j <= t[i]; j++)
  27. {
  28. sum += double(x[i]) - orta;
  29. if(sum < 0)
  30. sum = 0.0;
  31. if(sum > (double)(c))
  32. {
  33. a = orta;
  34. ok = true;
  35. }
  36. }
  37. }
  38. if(!ok)
  39. b = orta;
  40.  
  41. // cout << a << " " << b << '\n';
  42. //cout << a << " " << orta << " " << b << "\n";
  43. }
  44. printf("%lf %lf", a, b);
  45. // cout << a << "!" << b;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement