#include <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
using namespace std;
signed main()
{
int n;
cin >> n;
vector<pair<int, int>> a(n + 1);
vector<pair<int, int>> b(n);
for(int i = 0; i <= n; i ++)
{
cin >> a[i].first;
a[i].second = i;
}
for(int i = 0; i < n; i ++)
{
cin >> b[i].first;
b[i].second = i;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> cl(n);
vector<int> cr(n);
for(int i = 0; i < n; i ++)
{
cl[i] = max(int(0), a[i].first - b[i].first);
cr[i] = max(int(0), a[i + 1].first - b[i].first);
}
vector<int> ml(n + 1);
vector<int> mr(n + 1);
int mlval = 0;
int mrval = 0;
for(int i = 1; i <= n; i ++)
{
mlval = max(mlval, cl[i - 1]);
ml[i] = mlval;
}
for(int i = n - 1; i >= 0; i --)
{
mrval = max(mrval, cr[i]);
mr[i] = mrval;
}
vector<int> ans0(n + 1);
for(int i = 0; i <= n; i ++) ans0[i] = max(ml[i], mr[i]);
vector<int> ans(n + 1);
for(int i = 0; i <= n; i ++) ans[a[i].second] = ans0[i];
for(int el : ans) cout << el << " ";
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
3 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
492 KB |
Output is correct |
24 |
Correct |
3 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
444 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
492 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
20 |
Correct |
2 ms |
492 KB |
Output is correct |
21 |
Correct |
3 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
492 KB |
Output is correct |
24 |
Correct |
3 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
444 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
240 ms |
16748 KB |
Output is correct |
34 |
Correct |
249 ms |
17516 KB |
Output is correct |
35 |
Correct |
277 ms |
16824 KB |
Output is correct |
36 |
Correct |
272 ms |
17388 KB |
Output is correct |
37 |
Correct |
264 ms |
17900 KB |
Output is correct |
38 |
Correct |
254 ms |
17772 KB |
Output is correct |
39 |
Correct |
260 ms |
16748 KB |
Output is correct |
40 |
Correct |
260 ms |
16620 KB |
Output is correct |
41 |
Correct |
244 ms |
16896 KB |
Output is correct |
42 |
Correct |
246 ms |
16748 KB |
Output is correct |
43 |
Correct |
242 ms |
16748 KB |
Output is correct |
44 |
Correct |
251 ms |
16236 KB |
Output is correct |
45 |
Correct |
244 ms |
16492 KB |
Output is correct |
46 |
Correct |
237 ms |
16108 KB |
Output is correct |
47 |
Correct |
250 ms |
16512 KB |
Output is correct |
48 |
Correct |
252 ms |
16492 KB |
Output is correct |
49 |
Correct |
252 ms |
17132 KB |
Output is correct |
50 |
Correct |
255 ms |
17132 KB |
Output is correct |
51 |
Correct |
253 ms |
17132 KB |
Output is correct |
52 |
Correct |
250 ms |
17132 KB |
Output is correct |
53 |
Correct |
251 ms |
17132 KB |
Output is correct |