#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, i;
pair<int,int> p[N];
cin>>n;
for(i = 0; i < n + 1; i++)
{
cin>>p[i].first;
p[i].second = i;
}
int b[N];
for(i = 0; i < n; i++)
cin>>b[i];
sort(p, p + n + 1);
sort(b, b + n);
int m[N];
m[0] = max(p[0].first - b[0], 0);
for(i = 1; i < n; i++)
m[i] = max(m[i-1], p[i].first - b[i]);
int ans[N], cm = 0;
for(i = n; i > 0; i--)
{
ans[p[i].second] = max(m[i-1], cm);
cm = max(cm, p[i].first - b[i-1]);
}
ans[p[i].second] = cm;
for(i = 0; i < n + 1; i++)
cout<<ans[i]<<"\n "[i!=n];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
1 ms |
1920 KB |
Output is correct |
3 |
Correct |
2 ms |
1920 KB |
Output is correct |
4 |
Correct |
2 ms |
1920 KB |
Output is correct |
5 |
Correct |
1 ms |
1920 KB |
Output is correct |
6 |
Correct |
1 ms |
1920 KB |
Output is correct |
7 |
Correct |
2 ms |
1920 KB |
Output is correct |
8 |
Correct |
2 ms |
2048 KB |
Output is correct |
9 |
Correct |
1 ms |
1920 KB |
Output is correct |
10 |
Correct |
2 ms |
1920 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
1 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
1 ms |
1920 KB |
Output is correct |
3 |
Correct |
2 ms |
1920 KB |
Output is correct |
4 |
Correct |
2 ms |
1920 KB |
Output is correct |
5 |
Correct |
1 ms |
1920 KB |
Output is correct |
6 |
Correct |
1 ms |
1920 KB |
Output is correct |
7 |
Correct |
2 ms |
1920 KB |
Output is correct |
8 |
Correct |
2 ms |
2048 KB |
Output is correct |
9 |
Correct |
1 ms |
1920 KB |
Output is correct |
10 |
Correct |
2 ms |
1920 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
1 ms |
1920 KB |
Output is correct |
13 |
Correct |
1 ms |
1920 KB |
Output is correct |
14 |
Correct |
3 ms |
1920 KB |
Output is correct |
15 |
Correct |
2 ms |
2048 KB |
Output is correct |
16 |
Correct |
1 ms |
1920 KB |
Output is correct |
17 |
Correct |
2 ms |
2048 KB |
Output is correct |
18 |
Correct |
3 ms |
2048 KB |
Output is correct |
19 |
Correct |
2 ms |
2048 KB |
Output is correct |
20 |
Correct |
3 ms |
2048 KB |
Output is correct |
21 |
Correct |
2 ms |
2048 KB |
Output is correct |
22 |
Correct |
3 ms |
2048 KB |
Output is correct |
23 |
Correct |
2 ms |
2048 KB |
Output is correct |
24 |
Correct |
3 ms |
2048 KB |
Output is correct |
25 |
Correct |
2 ms |
2048 KB |
Output is correct |
26 |
Correct |
2 ms |
2048 KB |
Output is correct |
27 |
Correct |
2 ms |
2048 KB |
Output is correct |
28 |
Correct |
2 ms |
2048 KB |
Output is correct |
29 |
Correct |
3 ms |
1920 KB |
Output is correct |
30 |
Correct |
3 ms |
2048 KB |
Output is correct |
31 |
Correct |
3 ms |
2048 KB |
Output is correct |
32 |
Correct |
2 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1920 KB |
Output is correct |
2 |
Correct |
1 ms |
1920 KB |
Output is correct |
3 |
Correct |
2 ms |
1920 KB |
Output is correct |
4 |
Correct |
2 ms |
1920 KB |
Output is correct |
5 |
Correct |
1 ms |
1920 KB |
Output is correct |
6 |
Correct |
1 ms |
1920 KB |
Output is correct |
7 |
Correct |
2 ms |
1920 KB |
Output is correct |
8 |
Correct |
2 ms |
2048 KB |
Output is correct |
9 |
Correct |
1 ms |
1920 KB |
Output is correct |
10 |
Correct |
2 ms |
1920 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
1 ms |
1920 KB |
Output is correct |
13 |
Correct |
1 ms |
1920 KB |
Output is correct |
14 |
Correct |
3 ms |
1920 KB |
Output is correct |
15 |
Correct |
2 ms |
2048 KB |
Output is correct |
16 |
Correct |
1 ms |
1920 KB |
Output is correct |
17 |
Correct |
2 ms |
2048 KB |
Output is correct |
18 |
Correct |
3 ms |
2048 KB |
Output is correct |
19 |
Correct |
2 ms |
2048 KB |
Output is correct |
20 |
Correct |
3 ms |
2048 KB |
Output is correct |
21 |
Correct |
2 ms |
2048 KB |
Output is correct |
22 |
Correct |
3 ms |
2048 KB |
Output is correct |
23 |
Correct |
2 ms |
2048 KB |
Output is correct |
24 |
Correct |
3 ms |
2048 KB |
Output is correct |
25 |
Correct |
2 ms |
2048 KB |
Output is correct |
26 |
Correct |
2 ms |
2048 KB |
Output is correct |
27 |
Correct |
2 ms |
2048 KB |
Output is correct |
28 |
Correct |
2 ms |
2048 KB |
Output is correct |
29 |
Correct |
3 ms |
1920 KB |
Output is correct |
30 |
Correct |
3 ms |
2048 KB |
Output is correct |
31 |
Correct |
3 ms |
2048 KB |
Output is correct |
32 |
Correct |
2 ms |
2048 KB |
Output is correct |
33 |
Correct |
112 ms |
9336 KB |
Output is correct |
34 |
Correct |
117 ms |
9720 KB |
Output is correct |
35 |
Correct |
111 ms |
9464 KB |
Output is correct |
36 |
Correct |
116 ms |
9976 KB |
Output is correct |
37 |
Correct |
117 ms |
10104 KB |
Output is correct |
38 |
Correct |
118 ms |
9976 KB |
Output is correct |
39 |
Correct |
113 ms |
9080 KB |
Output is correct |
40 |
Correct |
115 ms |
9080 KB |
Output is correct |
41 |
Correct |
114 ms |
9208 KB |
Output is correct |
42 |
Correct |
113 ms |
9080 KB |
Output is correct |
43 |
Correct |
113 ms |
9080 KB |
Output is correct |
44 |
Correct |
107 ms |
8696 KB |
Output is correct |
45 |
Correct |
112 ms |
8824 KB |
Output is correct |
46 |
Correct |
109 ms |
8696 KB |
Output is correct |
47 |
Correct |
102 ms |
8696 KB |
Output is correct |
48 |
Correct |
107 ms |
8696 KB |
Output is correct |
49 |
Correct |
113 ms |
9340 KB |
Output is correct |
50 |
Correct |
110 ms |
9336 KB |
Output is correct |
51 |
Correct |
110 ms |
9336 KB |
Output is correct |
52 |
Correct |
112 ms |
9336 KB |
Output is correct |
53 |
Correct |
110 ms |
9336 KB |
Output is correct |