#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<pair<int,int>> A(N+1); vector<int> ord(N+1);
for(int i = 0;i<=N;++i){
cin >> A[i].f;
A[i].s = 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) ord[A[i].s] = i;
vector<int> pref(N);
for(int i = 0;i<N;++i){
if(i > 0) pref[i] = max(pref[i-1],max(A[i].f-B[i],0));
else pref[i] = max(A[i].f-B[i],0);
}
vector<int> suf(N); //suf[N-1] starts at the last value of B and this time also the last value of A, so i+1 for A
for(int i = N-1;i>=0;--i){
if(i < N-1) suf[i] = max(suf[i+1],max(A[i+1].f-B[i],0));
else suf[i] = max(A[i+1].f-B[i],0);
}
for(int i = 0;i<=N;++i){
//cout << ord[i] << "\n";
if(ord[i] == 0){
cout << suf[0];
}
else if(ord[i] == N){
cout << pref[N-1];
}
else{
cout << max(pref[ord[i]-1],suf[ord[i]]);
}
//cout << "\n";
if(i != N) cout << " ";
else cout << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
344 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 |
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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
0 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 |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
468 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 |
344 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 |
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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
0 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 |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 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 |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
468 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 |
63 ms |
10064 KB |
Output is correct |
34 |
Correct |
61 ms |
10320 KB |
Output is correct |
35 |
Correct |
58 ms |
9980 KB |
Output is correct |
36 |
Correct |
56 ms |
10548 KB |
Output is correct |
37 |
Correct |
61 ms |
10832 KB |
Output is correct |
38 |
Correct |
60 ms |
10832 KB |
Output is correct |
39 |
Correct |
57 ms |
9808 KB |
Output is correct |
40 |
Correct |
60 ms |
9824 KB |
Output is correct |
41 |
Correct |
56 ms |
9916 KB |
Output is correct |
42 |
Correct |
57 ms |
9808 KB |
Output is correct |
43 |
Correct |
55 ms |
9792 KB |
Output is correct |
44 |
Correct |
55 ms |
9296 KB |
Output is correct |
45 |
Correct |
53 ms |
9464 KB |
Output is correct |
46 |
Correct |
55 ms |
9300 KB |
Output is correct |
47 |
Correct |
49 ms |
9536 KB |
Output is correct |
48 |
Correct |
51 ms |
9552 KB |
Output is correct |
49 |
Correct |
56 ms |
10068 KB |
Output is correct |
50 |
Correct |
60 ms |
10096 KB |
Output is correct |
51 |
Correct |
59 ms |
10068 KB |
Output is correct |
52 |
Correct |
62 ms |
10064 KB |
Output is correct |
53 |
Correct |
57 ms |
10064 KB |
Output is correct |