import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class ho_t1 {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(in.readLine());
int N = Integer.parseInt(st.nextToken());
int[][] A = new int[N+1][2];
int[][] B = new int[N][1];
st = new StringTokenizer(in.readLine());
for (int i = 0; i <= N; i++) {
A[i][0] = Integer.parseInt(st.nextToken());
A[i][1] = i;
}
st = new StringTokenizer(in.readLine());
for (int i = 0; i < N; i++) {
B[i][0] = Integer.parseInt(st.nextToken());
}
Arrays.sort(B, new Comparator<int[]>() {
@Override
public int compare(int[] ints, int[] t1) {
return Integer.compare(ints[0], t1[0]);
}
});
Arrays.sort(A, new Comparator<int[]>() {
@Override
public int compare(int[] ints, int[] t1) {
return Integer.compare(ints[0], t1[0]);
}
});
int[] prefMax = new int[N];
prefMax[0] = A[0][0] - B[0][0];
for (int i = 1; i < N; i++) {
prefMax[i] = Math.max(prefMax[i-1], A[i][0] - B[i][0]);
}
int suffixMax = 0;
int[] ans = new int[N+1];
for (int i = N; i >= 1; i--) {
ans[A[i][1]] = Math.max(0, Math.max(suffixMax, prefMax[i-1]));
suffixMax = Math.max(A[i][0] - B[i-1][0], suffixMax);
}
ans[A[0][1]] = Math.max(0, suffixMax);
for (int i : ans) {
out.print(i + " ");
}
out.close();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
10460 KB |
Output is correct |
2 |
Correct |
84 ms |
10428 KB |
Output is correct |
3 |
Correct |
80 ms |
10216 KB |
Output is correct |
4 |
Correct |
77 ms |
10108 KB |
Output is correct |
5 |
Correct |
76 ms |
10344 KB |
Output is correct |
6 |
Correct |
79 ms |
10216 KB |
Output is correct |
7 |
Correct |
80 ms |
10376 KB |
Output is correct |
8 |
Correct |
77 ms |
10216 KB |
Output is correct |
9 |
Correct |
85 ms |
10508 KB |
Output is correct |
10 |
Correct |
76 ms |
10232 KB |
Output is correct |
11 |
Correct |
83 ms |
10360 KB |
Output is correct |
12 |
Correct |
82 ms |
10432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
10460 KB |
Output is correct |
2 |
Correct |
84 ms |
10428 KB |
Output is correct |
3 |
Correct |
80 ms |
10216 KB |
Output is correct |
4 |
Correct |
77 ms |
10108 KB |
Output is correct |
5 |
Correct |
76 ms |
10344 KB |
Output is correct |
6 |
Correct |
79 ms |
10216 KB |
Output is correct |
7 |
Correct |
80 ms |
10376 KB |
Output is correct |
8 |
Correct |
77 ms |
10216 KB |
Output is correct |
9 |
Correct |
85 ms |
10508 KB |
Output is correct |
10 |
Correct |
76 ms |
10232 KB |
Output is correct |
11 |
Correct |
83 ms |
10360 KB |
Output is correct |
12 |
Correct |
82 ms |
10432 KB |
Output is correct |
13 |
Correct |
86 ms |
10592 KB |
Output is correct |
14 |
Correct |
106 ms |
11240 KB |
Output is correct |
15 |
Correct |
134 ms |
12152 KB |
Output is correct |
16 |
Correct |
83 ms |
10380 KB |
Output is correct |
17 |
Correct |
151 ms |
12560 KB |
Output is correct |
18 |
Correct |
131 ms |
12280 KB |
Output is correct |
19 |
Correct |
143 ms |
12264 KB |
Output is correct |
20 |
Correct |
140 ms |
12644 KB |
Output is correct |
21 |
Correct |
138 ms |
12020 KB |
Output is correct |
22 |
Correct |
137 ms |
12240 KB |
Output is correct |
23 |
Correct |
139 ms |
12096 KB |
Output is correct |
24 |
Correct |
142 ms |
12324 KB |
Output is correct |
25 |
Correct |
167 ms |
12808 KB |
Output is correct |
26 |
Correct |
165 ms |
12488 KB |
Output is correct |
27 |
Correct |
142 ms |
12520 KB |
Output is correct |
28 |
Correct |
145 ms |
12172 KB |
Output is correct |
29 |
Correct |
126 ms |
11464 KB |
Output is correct |
30 |
Correct |
145 ms |
12492 KB |
Output is correct |
31 |
Correct |
147 ms |
12736 KB |
Output is correct |
32 |
Correct |
136 ms |
11768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
10460 KB |
Output is correct |
2 |
Correct |
84 ms |
10428 KB |
Output is correct |
3 |
Correct |
80 ms |
10216 KB |
Output is correct |
4 |
Correct |
77 ms |
10108 KB |
Output is correct |
5 |
Correct |
76 ms |
10344 KB |
Output is correct |
6 |
Correct |
79 ms |
10216 KB |
Output is correct |
7 |
Correct |
80 ms |
10376 KB |
Output is correct |
8 |
Correct |
77 ms |
10216 KB |
Output is correct |
9 |
Correct |
85 ms |
10508 KB |
Output is correct |
10 |
Correct |
76 ms |
10232 KB |
Output is correct |
11 |
Correct |
83 ms |
10360 KB |
Output is correct |
12 |
Correct |
82 ms |
10432 KB |
Output is correct |
13 |
Correct |
86 ms |
10592 KB |
Output is correct |
14 |
Correct |
106 ms |
11240 KB |
Output is correct |
15 |
Correct |
134 ms |
12152 KB |
Output is correct |
16 |
Correct |
83 ms |
10380 KB |
Output is correct |
17 |
Correct |
151 ms |
12560 KB |
Output is correct |
18 |
Correct |
131 ms |
12280 KB |
Output is correct |
19 |
Correct |
143 ms |
12264 KB |
Output is correct |
20 |
Correct |
140 ms |
12644 KB |
Output is correct |
21 |
Correct |
138 ms |
12020 KB |
Output is correct |
22 |
Correct |
137 ms |
12240 KB |
Output is correct |
23 |
Correct |
139 ms |
12096 KB |
Output is correct |
24 |
Correct |
142 ms |
12324 KB |
Output is correct |
25 |
Correct |
167 ms |
12808 KB |
Output is correct |
26 |
Correct |
165 ms |
12488 KB |
Output is correct |
27 |
Correct |
142 ms |
12520 KB |
Output is correct |
28 |
Correct |
145 ms |
12172 KB |
Output is correct |
29 |
Correct |
126 ms |
11464 KB |
Output is correct |
30 |
Correct |
145 ms |
12492 KB |
Output is correct |
31 |
Correct |
147 ms |
12736 KB |
Output is correct |
32 |
Correct |
136 ms |
11768 KB |
Output is correct |
33 |
Execution timed out |
1014 ms |
70224 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |