#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
int add(int a, int b){
a += b;
if(a >= MOD){
a -= MOD;
}
return a;
}
int sub(int a, int b){
a -= b;
if(a < 0) a += MOD;
return a;
}
int mult(int a, int b){
return ((ll) a * b) % MOD;
}
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen((s+".in").c_str(),"r",stdin);
// freopen((s+".text").c_str(),"w",stdout);
}
//ctrl q is comment
//ctrl b is run
//ctrl s is compile
//alt r is search & replace
//alt d is delete a line
int main(){
setIO();
int N; cin >> N;
pii A[N + 1];
int B[N];
for(int i = 0; i <= N; ++i){
cin >> A[i].x;
A[i].y = i;
}
for(int i = 0; i < N; ++i){
cin >> B[i];
}
sort(A, A + N + 1);
sort(B, B + N);
int ans[N + 1], dif1[N], dif2[N], suffmx[N], prefmx[N];
fill(ans, ans + N + 1, 0);
for(int i = 0; i < N; ++i) {
dif1[i] = max(A[i].x - B[i], 0);
dif2[i] = max(A[i + 1].x - B[i], 0);
}
for(int i = 0; i < N; ++i) {
prefmx[i] = dif1[i];
if(i > 0) prefmx[i] = max(prefmx[i - 1], prefmx[i]);
}
for(int i = N - 1; i >= 0; --i) {
suffmx[i] = dif2[i];
if(i < N - 1) suffmx[i] = max(suffmx[i], suffmx[i + 1]);
}
for(int i = 0; i <= N; ++i) {
if(i > 0) ans[A[i].y] = prefmx[i - 1];
if(i < N) ans[A[i].y] = max(ans[A[i].y], suffmx[i]);
}
for(int i = 0; i <= N; ++i) {
cout << ans[i] << " ";
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
404 KB |
Output is correct |
33 |
Correct |
98 ms |
8184 KB |
Output is correct |
34 |
Correct |
109 ms |
8824 KB |
Output is correct |
35 |
Correct |
101 ms |
8568 KB |
Output is correct |
36 |
Correct |
103 ms |
8952 KB |
Output is correct |
37 |
Correct |
106 ms |
9208 KB |
Output is correct |
38 |
Correct |
107 ms |
9128 KB |
Output is correct |
39 |
Correct |
110 ms |
8176 KB |
Output is correct |
40 |
Correct |
101 ms |
8184 KB |
Output is correct |
41 |
Correct |
100 ms |
8316 KB |
Output is correct |
42 |
Correct |
104 ms |
8312 KB |
Output is correct |
43 |
Correct |
98 ms |
8184 KB |
Output is correct |
44 |
Correct |
97 ms |
7800 KB |
Output is correct |
45 |
Correct |
100 ms |
7928 KB |
Output is correct |
46 |
Correct |
98 ms |
7800 KB |
Output is correct |
47 |
Correct |
93 ms |
7800 KB |
Output is correct |
48 |
Correct |
96 ms |
7900 KB |
Output is correct |
49 |
Correct |
102 ms |
8440 KB |
Output is correct |
50 |
Correct |
102 ms |
8440 KB |
Output is correct |
51 |
Correct |
102 ms |
8440 KB |
Output is correct |
52 |
Correct |
101 ms |
8440 KB |
Output is correct |
53 |
Correct |
102 ms |
8440 KB |
Output is correct |