#include<bits/stdc++.h>
#ifdef _DEBUG
#define ls(x) << (x) << ", "
#define lv(x) << #x << ": " << flush << (x) << ", "
#define pr(x) cout << "Line: " << __LINE__ << ", " x << endl;
#else
#define ls(x)
#define lv(x)
#define pr(x) ;
#endif
using namespace std;
typedef unsigned int uint;
struct Neckle {
int a;
uint i;
};
bool operator<(Neckle a, Neckle b) {
return a.a < b.a;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
uint n;
cin >> n;
vector<Neckle> a(n+1), b(n);
for (uint i = 0; i < n+1; i++) {
cin >> a[i].a;
a[i].i = i;
}
for (uint i = 0; i < n; i++) {
cin >> b[i].a;
b[i].i = i;
}
// if (n == 1) {
// cout << abs((int)a[1].a - (int)b[0].a) << ' '
// << abs((int)a[0].a - (int)b[0].a);
// return 0;
// }
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<int> pref(n + 1), suff(n + 1);
pref[0] = 0;
for (uint i = 1; i < n + 1; i++) {
pr(lv(i) lv(a[i].a) lv(b[i].a))
pref[i] = max(pref[i - 1], a[i - 1].a - b[i - 1].a);
}
suff[n] = 0;
// suff[i] = a[i+1].a - b[i].a
for (uint i = n-1; i + 1 > 0; i--) {
pr(lv(i) lv(a[i + 1].a) lv(b[i].a))
suff[i] = max(suff[i+1], a[i+1].a - b[i].a);
}
vector<uint> mapping(n+1);
for (uint i = 0; i < n+1; i++) {
mapping[a[i].i] = i;
pr(lv(i) lv(a[i].a) lv(a[i].i) lv(mapping[a[i].i]))
}
for (uint i = 0; i < n+1; i++) {
uint k = mapping[i];
pr(lv(i) lv(k) lv(suff[k]) lv(pref[k]))
uint result = max(suff[k], pref[k]);
cout << result << " ";
pr(lv(i) lv(k) lv(result))
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
472 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
476 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
648 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
472 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
476 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
648 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
68 ms |
10824 KB |
Output is correct |
34 |
Correct |
69 ms |
11220 KB |
Output is correct |
35 |
Correct |
67 ms |
10824 KB |
Output is correct |
36 |
Correct |
71 ms |
11056 KB |
Output is correct |
37 |
Correct |
71 ms |
11592 KB |
Output is correct |
38 |
Correct |
77 ms |
11592 KB |
Output is correct |
39 |
Correct |
67 ms |
10312 KB |
Output is correct |
40 |
Correct |
73 ms |
7240 KB |
Output is correct |
41 |
Correct |
69 ms |
7464 KB |
Output is correct |
42 |
Correct |
69 ms |
10644 KB |
Output is correct |
43 |
Correct |
72 ms |
10436 KB |
Output is correct |
44 |
Correct |
72 ms |
7496 KB |
Output is correct |
45 |
Correct |
76 ms |
10312 KB |
Output is correct |
46 |
Correct |
70 ms |
10056 KB |
Output is correct |
47 |
Correct |
57 ms |
10312 KB |
Output is correct |
48 |
Correct |
58 ms |
9884 KB |
Output is correct |
49 |
Correct |
73 ms |
10828 KB |
Output is correct |
50 |
Correct |
74 ms |
10568 KB |
Output is correct |
51 |
Correct |
71 ms |
10824 KB |
Output is correct |
52 |
Correct |
81 ms |
10824 KB |
Output is correct |
53 |
Correct |
88 ms |
10824 KB |
Output is correct |