# Untitled

a guest
Apr 24th, 2016
254
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <cmath>
3.
4. using namespace std;
5.
6. const int MAXN = 100 * 1000 + 5;
7. const long double EPS = 1e-9;
8. long double a[MAXN], b[MAXN], p[MAXN], q[MAXN];
9.
10. pair<long double, long double> solve(long double p, long double q) {
11.     long double d = sqrt(p * p - 4 * q);
12.     return make_pair((-p + d) / 2, (-p - d) / 2);
13. }
14.
15. int main() {
16.     ios_base::sync_with_stdio(false);
17.     cin.tie(0);
18.     cout.setf(ios::fixed);
19.     cout.precision(9);
20.     int n;
21.     cin >> n;
22.     for(int i = 0; i < n; i++)
23.         cin >> a[i];
24.     for(int i = 0; i < n; i++)
25.         cin >> b[i];
26.     for(int i = 0; i + 1 < n; i++)
27.         a[i + 1] += a[i];
28.     for(int i = n - 1; i > 0; i--)
29.         b[i - 1] += b[i];
30.     for(int i = 0; i < n; i++) {
31.         pair<long double, long double> pp = solve(b[i + 1] - a[i] - 1, a[i]);
32.         if(i > 0 && (p[i - 1] > pp.first - EPS || q[i - 1] > pp.second - EPS))
33.             swap(pp.first, pp.second);
34.         p[i] = pp.first;
35.         q[i] = pp.second;
36.     }
37.     for(int i = 0; i < n; i++)
38.         cout << p[i] - (i? p[i - 1] : 0) << ' ';
39.     cout << '\n';
40.     for(int i = 0; i < n; i++)
41.         cout << q[i] - (i? q[i - 1] : 0) << ' ';
42.     cout << '\n';
43.     return 0;
44. }
RAW Paste Data

# Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×