#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<pair<int,int>> A(N + 1);
vector<int> O(N + 1);
for(int i = 0;i <= N; ++i){
cin >> A[i].first;
A[i].second = i;
}
vector<int> B(N);
for(int i = 0;i < N; ++i){
cin >> B[i];
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
for(int i = 0;i <= N; ++i) O[A[i].second] = i;
vector<int> pref(N);
for(int i = 0;i < N; ++i){
if(i > 0) pref[i] = max(pref[i - 1], max(A[i].first - B[i], 0));
else pref[i] = max(A[i].first - B[i], 0);
}
vector<int> suf(N);
for(int i = N - 1;i >= 0; --i){
if(i < N-1) suf[i] = max(suf[i + 1],max(A[i + 1].first - B[i],0));
else suf[i] = max(A[i + 1].first - B[i],0);
}
for(int i = 0;i <= N; ++i){
if(O[i] == 0){
cout << suf[0];
}
else if(O[i] == N){
cout << pref[N-1];
}
else{
cout << max(pref[O[i] - 1], suf[O[i]]);
}
if(i != N) cout << " ";
else cout << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
508 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 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 |
488 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
500 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
508 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 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 |
488 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
500 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
117 ms |
9904 KB |
Output is correct |
34 |
Correct |
121 ms |
10320 KB |
Output is correct |
35 |
Correct |
149 ms |
10064 KB |
Output is correct |
36 |
Correct |
109 ms |
10580 KB |
Output is correct |
37 |
Correct |
115 ms |
10836 KB |
Output is correct |
38 |
Correct |
115 ms |
10660 KB |
Output is correct |
39 |
Correct |
113 ms |
9784 KB |
Output is correct |
40 |
Correct |
114 ms |
9740 KB |
Output is correct |
41 |
Correct |
114 ms |
9744 KB |
Output is correct |
42 |
Correct |
121 ms |
9880 KB |
Output is correct |
43 |
Correct |
109 ms |
9808 KB |
Output is correct |
44 |
Correct |
105 ms |
9296 KB |
Output is correct |
45 |
Correct |
107 ms |
9328 KB |
Output is correct |
46 |
Correct |
108 ms |
9372 KB |
Output is correct |
47 |
Correct |
123 ms |
9536 KB |
Output is correct |
48 |
Correct |
106 ms |
9556 KB |
Output is correct |
49 |
Correct |
111 ms |
10060 KB |
Output is correct |
50 |
Correct |
111 ms |
10068 KB |
Output is correct |
51 |
Correct |
112 ms |
9936 KB |
Output is correct |
52 |
Correct |
116 ms |
9924 KB |
Output is correct |
53 |
Correct |
147 ms |
10048 KB |
Output is correct |