#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> B(N);
for(int i = 0;i<=N;++i){
cin >> A[i].f;
A[i].s = i;
}
for(int i = 0;i<N;++i) cin >> B[i];
sort(A.begin(),A.end()); sort(B.begin(),B.end());
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);
//cout << pref[i] << "\n";
}
vector<int> suf(N+1);
for(int i = N;i>=1;--i){
if(i != N) suf[i] = max(suf[i+1],max(A[i].f-B[i-1],0));
else suf[i] = max(A[i].f-B[i-1],0);
}
vector<int> ans(N+1);
for(int i = 0;i<=N;++i){
if(i != N && i != 0) ans[A[i].s] = max(suf[i+1],pref[i-1]);
else if(i == N) ans[A[i].s] = pref[i-1];
else ans[A[i].s] = suf[i+1];
}
for(int i = 0;i<=N;++i) cout << ans[i] << " ";
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
520 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
720 KB |
Output is correct |
26 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
520 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
720 KB |
Output is correct |
26 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
536 KB |
Output is correct |
33 |
Correct |
75 ms |
10068 KB |
Output is correct |
34 |
Correct |
69 ms |
10448 KB |
Output is correct |
35 |
Correct |
67 ms |
9992 KB |
Output is correct |
36 |
Correct |
69 ms |
10580 KB |
Output is correct |
37 |
Correct |
74 ms |
10848 KB |
Output is correct |
38 |
Correct |
78 ms |
10676 KB |
Output is correct |
39 |
Correct |
69 ms |
9752 KB |
Output is correct |
40 |
Correct |
72 ms |
9808 KB |
Output is correct |
41 |
Correct |
71 ms |
10124 KB |
Output is correct |
42 |
Correct |
67 ms |
9808 KB |
Output is correct |
43 |
Correct |
69 ms |
9796 KB |
Output is correct |
44 |
Correct |
67 ms |
9300 KB |
Output is correct |
45 |
Correct |
68 ms |
9476 KB |
Output is correct |
46 |
Correct |
66 ms |
9300 KB |
Output is correct |
47 |
Correct |
64 ms |
9516 KB |
Output is correct |
48 |
Correct |
63 ms |
9556 KB |
Output is correct |
49 |
Correct |
70 ms |
9996 KB |
Output is correct |
50 |
Correct |
71 ms |
10068 KB |
Output is correct |
51 |
Correct |
69 ms |
10064 KB |
Output is correct |
52 |
Correct |
69 ms |
10072 KB |
Output is correct |
53 |
Correct |
70 ms |
10068 KB |
Output is correct |