#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int b[MAXN], cuPrimul[MAXN], cuUltimul[MAXN], ans[MAXN];
struct A{
int a, pozInit;
};
A v[MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, i;
cin >> n;
for(i = 1; i <= n + 1; i++){
cin >> v[i].a;
v[i].pozInit = i;
}
for(i = 1; i <= n; i++){
cin >> b[i];
}
sort(v, v + n + 2, [](A e1, A e2){
return (e1.a < e2.a);
});
sort(b, b + n + 1);
// cuPrimul[i] = oddity of party until now (this vector includes the first element but excludes the last (a[i] - b[i])
for(i = 1; i <= n + 1; i++){
cuPrimul[i] = max(cuPrimul[i - 1], max(v[i].a - b[i], 0)); // oddity of party = maximum strangeness; strangeness = max{a − b, 0}
}
// cuUltimul[i] = oddity of party until now (this vector excludes the first element but includes the last (a[i + 1] - b[i])
for(i = n + 1; i >= 1; i--){
cuUltimul[i] = max(cuUltimul[i + 1], max(v[i + 1].a - b[i], 0));
}
for(i = 0; i <= n; i++){
ans[v[i + 1].pozInit] = max(cuPrimul[i], cuUltimul[i + 1]);
}
for(i = 1; i <= n + 1; i++){
cout << ans[i] << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 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 |
2 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 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 |
2 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 |
68 ms |
9956 KB |
Output is correct |
34 |
Correct |
71 ms |
10300 KB |
Output is correct |
35 |
Correct |
68 ms |
10004 KB |
Output is correct |
36 |
Correct |
69 ms |
10440 KB |
Output is correct |
37 |
Correct |
71 ms |
10732 KB |
Output is correct |
38 |
Correct |
70 ms |
10680 KB |
Output is correct |
39 |
Correct |
69 ms |
9700 KB |
Output is correct |
40 |
Correct |
68 ms |
9752 KB |
Output is correct |
41 |
Correct |
70 ms |
9836 KB |
Output is correct |
42 |
Correct |
68 ms |
9804 KB |
Output is correct |
43 |
Correct |
67 ms |
9700 KB |
Output is correct |
44 |
Correct |
66 ms |
9288 KB |
Output is correct |
45 |
Correct |
67 ms |
9360 KB |
Output is correct |
46 |
Correct |
73 ms |
9428 KB |
Output is correct |
47 |
Correct |
66 ms |
9340 KB |
Output is correct |
48 |
Correct |
55 ms |
9376 KB |
Output is correct |
49 |
Correct |
70 ms |
10036 KB |
Output is correct |
50 |
Correct |
75 ms |
10040 KB |
Output is correct |
51 |
Correct |
72 ms |
9960 KB |
Output is correct |
52 |
Correct |
71 ms |
9992 KB |
Output is correct |
53 |
Correct |
70 ms |
9932 KB |
Output is correct |