#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int main() {
// freopen("moocast.in", "r", stdin);
// freopen("moocast.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, i, s;
cin >> n;
ll ans[n + 2];
pair < ll, ll > A[n + 2];
ll b[n + 2], aragshaa[n + 2], uragshaa[n + 2], Pre[n + 2], Suf[n + 2];
for (i = 1; i <= n + 1; i ++) {
cin >> A[i].first;
A[i].second = i;
}
for (i = 1; i <= n; i ++) {
cin >> b[i];
}
sort ( b + 1, b + n + 1);
sort ( A + 1, A + n + 2);
for (i = 1; i <= n; i ++) {
uragshaa[i] = max(0ll, A[i].first - b[i]);
aragshaa[i] = max(0ll, A[i + 1].first - b[i]);
}
Pre[0]= 0;
for (i = 1; i <=n; i ++) {
Pre[i]= max(Pre[i - 1] , uragshaa[i]);
}
Suf[n + 1] = 0;
for (i = n; i >= 1; i --) {
Suf[i] = max(Suf[i + 1] , aragshaa[i]);
}
for (i = 1; i <= n + 1; i ++) {
s = max(Suf[i] , Pre[i - 1]);
ans[A[i].second] = s;
}
for (i = 1; i<= n + 1; i ++) cout << ans[i] << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
584 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
584 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
608 KB |
Output is correct |
33 |
Correct |
79 ms |
17520 KB |
Output is correct |
34 |
Correct |
78 ms |
18232 KB |
Output is correct |
35 |
Correct |
77 ms |
17488 KB |
Output is correct |
36 |
Correct |
74 ms |
18156 KB |
Output is correct |
37 |
Correct |
76 ms |
18536 KB |
Output is correct |
38 |
Correct |
79 ms |
18612 KB |
Output is correct |
39 |
Correct |
74 ms |
17492 KB |
Output is correct |
40 |
Correct |
75 ms |
17424 KB |
Output is correct |
41 |
Correct |
76 ms |
17504 KB |
Output is correct |
42 |
Correct |
74 ms |
17488 KB |
Output is correct |
43 |
Correct |
73 ms |
17344 KB |
Output is correct |
44 |
Correct |
73 ms |
16720 KB |
Output is correct |
45 |
Correct |
75 ms |
17232 KB |
Output is correct |
46 |
Correct |
72 ms |
16724 KB |
Output is correct |
47 |
Correct |
78 ms |
17264 KB |
Output is correct |
48 |
Correct |
70 ms |
17292 KB |
Output is correct |
49 |
Correct |
76 ms |
18004 KB |
Output is correct |
50 |
Correct |
76 ms |
18004 KB |
Output is correct |
51 |
Correct |
80 ms |
18004 KB |
Output is correct |
52 |
Correct |
89 ms |
17852 KB |
Output is correct |
53 |
Correct |
77 ms |
18004 KB |
Output is correct |