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];
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] = Integer.parseInt(st.nextToken());
}
Arrays.sort(B);
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];
for (int i = 1; i < N; i++) {
prefMax[i] = Math.max(prefMax[i-1], A[i][0] - B[i]);
}
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], suffixMax);
}
ans[A[0][1]] = Math.max(0, suffixMax);
for (int i : ans) {
out.print(i + " ");
}
out.close();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
10608 KB |
Output is correct |
2 |
Correct |
83 ms |
10228 KB |
Output is correct |
3 |
Correct |
79 ms |
10472 KB |
Output is correct |
4 |
Correct |
79 ms |
10104 KB |
Output is correct |
5 |
Correct |
78 ms |
10360 KB |
Output is correct |
6 |
Correct |
79 ms |
10232 KB |
Output is correct |
7 |
Correct |
76 ms |
10412 KB |
Output is correct |
8 |
Correct |
76 ms |
10344 KB |
Output is correct |
9 |
Correct |
88 ms |
10152 KB |
Output is correct |
10 |
Correct |
78 ms |
10340 KB |
Output is correct |
11 |
Correct |
89 ms |
10344 KB |
Output is correct |
12 |
Correct |
79 ms |
10212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
10608 KB |
Output is correct |
2 |
Correct |
83 ms |
10228 KB |
Output is correct |
3 |
Correct |
79 ms |
10472 KB |
Output is correct |
4 |
Correct |
79 ms |
10104 KB |
Output is correct |
5 |
Correct |
78 ms |
10360 KB |
Output is correct |
6 |
Correct |
79 ms |
10232 KB |
Output is correct |
7 |
Correct |
76 ms |
10412 KB |
Output is correct |
8 |
Correct |
76 ms |
10344 KB |
Output is correct |
9 |
Correct |
88 ms |
10152 KB |
Output is correct |
10 |
Correct |
78 ms |
10340 KB |
Output is correct |
11 |
Correct |
89 ms |
10344 KB |
Output is correct |
12 |
Correct |
79 ms |
10212 KB |
Output is correct |
13 |
Correct |
91 ms |
10744 KB |
Output is correct |
14 |
Correct |
111 ms |
11160 KB |
Output is correct |
15 |
Correct |
132 ms |
12464 KB |
Output is correct |
16 |
Correct |
87 ms |
10360 KB |
Output is correct |
17 |
Correct |
150 ms |
12332 KB |
Output is correct |
18 |
Correct |
138 ms |
13080 KB |
Output is correct |
19 |
Correct |
121 ms |
11640 KB |
Output is correct |
20 |
Correct |
142 ms |
12300 KB |
Output is correct |
21 |
Correct |
143 ms |
12136 KB |
Output is correct |
22 |
Correct |
137 ms |
13304 KB |
Output is correct |
23 |
Correct |
140 ms |
12052 KB |
Output is correct |
24 |
Correct |
140 ms |
12408 KB |
Output is correct |
25 |
Correct |
140 ms |
12436 KB |
Output is correct |
26 |
Correct |
139 ms |
13496 KB |
Output is correct |
27 |
Correct |
134 ms |
13288 KB |
Output is correct |
28 |
Correct |
142 ms |
13452 KB |
Output is correct |
29 |
Correct |
134 ms |
11640 KB |
Output is correct |
30 |
Correct |
139 ms |
12404 KB |
Output is correct |
31 |
Correct |
139 ms |
13276 KB |
Output is correct |
32 |
Correct |
135 ms |
12440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
10608 KB |
Output is correct |
2 |
Correct |
83 ms |
10228 KB |
Output is correct |
3 |
Correct |
79 ms |
10472 KB |
Output is correct |
4 |
Correct |
79 ms |
10104 KB |
Output is correct |
5 |
Correct |
78 ms |
10360 KB |
Output is correct |
6 |
Correct |
79 ms |
10232 KB |
Output is correct |
7 |
Correct |
76 ms |
10412 KB |
Output is correct |
8 |
Correct |
76 ms |
10344 KB |
Output is correct |
9 |
Correct |
88 ms |
10152 KB |
Output is correct |
10 |
Correct |
78 ms |
10340 KB |
Output is correct |
11 |
Correct |
89 ms |
10344 KB |
Output is correct |
12 |
Correct |
79 ms |
10212 KB |
Output is correct |
13 |
Correct |
91 ms |
10744 KB |
Output is correct |
14 |
Correct |
111 ms |
11160 KB |
Output is correct |
15 |
Correct |
132 ms |
12464 KB |
Output is correct |
16 |
Correct |
87 ms |
10360 KB |
Output is correct |
17 |
Correct |
150 ms |
12332 KB |
Output is correct |
18 |
Correct |
138 ms |
13080 KB |
Output is correct |
19 |
Correct |
121 ms |
11640 KB |
Output is correct |
20 |
Correct |
142 ms |
12300 KB |
Output is correct |
21 |
Correct |
143 ms |
12136 KB |
Output is correct |
22 |
Correct |
137 ms |
13304 KB |
Output is correct |
23 |
Correct |
140 ms |
12052 KB |
Output is correct |
24 |
Correct |
140 ms |
12408 KB |
Output is correct |
25 |
Correct |
140 ms |
12436 KB |
Output is correct |
26 |
Correct |
139 ms |
13496 KB |
Output is correct |
27 |
Correct |
134 ms |
13288 KB |
Output is correct |
28 |
Correct |
142 ms |
13452 KB |
Output is correct |
29 |
Correct |
134 ms |
11640 KB |
Output is correct |
30 |
Correct |
139 ms |
12404 KB |
Output is correct |
31 |
Correct |
139 ms |
13276 KB |
Output is correct |
32 |
Correct |
135 ms |
12440 KB |
Output is correct |
33 |
Execution timed out |
1339 ms |
60052 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |