Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define e (double)(1e-7)
- using namespace std;
- int n, t[51], x[51], c, maxi;
- double a, b;
- int main ()
- {
- cin >> n;
- for(int i = 1; i <= n; i++)
- cin >> t[i];
- for(int i = 1; i <= n; i++)
- {
- cin >> x[i];
- maxi = max(maxi, x[i]);
- }
- cin >> c;
- b = (double)(maxi);
- while(b - a > e)
- {
- double orta = (a + b) / 2;
- //cout << a << " " << orta << " " << b << " || ";
- double sum = 0.0;
- bool ok = false;
- for(int i = 1; i <= n; i++)
- {
- for(int j = 1; j <= t[i]; j++)
- {
- sum += double(x[i]) - orta;
- if(sum < 0)
- sum = 0.0;
- if(sum > (double)(c))
- {
- a = orta;
- ok = true;
- }
- }
- }
- if(!ok)
- b = orta;
- // cout << a << " " << b << '\n';
- //cout << a << " " << orta << " " << b << "\n";
- }
- printf("%lf %lf", a, b);
- // cout << a << "!" << b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement