#include <bits/stdc++.h>
using namespace std;
#define int long long
const int NM = 2e5;
struct necktie{
int id, l;
};
int N, B[NM+5], pref[NM+5], cur = 0, ans[NM+5];
necktie A[NM+5];
bool cmp(necktie a, necktie b){
return a.l < b.l;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N+1; i++){
cin >> A[i].l;
A[i].id = i;
}
for (int i = 1; i <= N; i++)
cin >> B[i];
sort(B+1, B+1+N);
sort(A+1, A+1+N+1, cmp);
for (int i = 1; i <= N; i++)
pref[i] = max(pref[i-1], max(A[i].l-B[i], 0LL));
cur = 0;
ans[A[N+1].id] = pref[N];
for (int i = N; i >= 1; i--){
cur = max(cur, max(A[i+1].l-B[i], 0LL));
ans[A[i].id] = max(pref[i-1], cur);
}
for (int i = 1; i <= N+1; i++) cout << ans[i] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
388 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
388 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
95 ms |
9304 KB |
Output is correct |
34 |
Correct |
74 ms |
9556 KB |
Output is correct |
35 |
Correct |
70 ms |
9304 KB |
Output is correct |
36 |
Correct |
74 ms |
9820 KB |
Output is correct |
37 |
Correct |
76 ms |
10120 KB |
Output is correct |
38 |
Correct |
73 ms |
9928 KB |
Output is correct |
39 |
Correct |
72 ms |
8984 KB |
Output is correct |
40 |
Correct |
73 ms |
8956 KB |
Output is correct |
41 |
Correct |
74 ms |
9148 KB |
Output is correct |
42 |
Correct |
77 ms |
9068 KB |
Output is correct |
43 |
Correct |
72 ms |
8976 KB |
Output is correct |
44 |
Correct |
69 ms |
8624 KB |
Output is correct |
45 |
Correct |
70 ms |
8672 KB |
Output is correct |
46 |
Correct |
70 ms |
8780 KB |
Output is correct |
47 |
Correct |
57 ms |
8588 KB |
Output is correct |
48 |
Correct |
58 ms |
8636 KB |
Output is correct |
49 |
Correct |
85 ms |
9232 KB |
Output is correct |
50 |
Correct |
73 ms |
9228 KB |
Output is correct |
51 |
Correct |
72 ms |
9232 KB |
Output is correct |
52 |
Correct |
73 ms |
9228 KB |
Output is correct |
53 |
Correct |
73 ms |
9232 KB |
Output is correct |