import java.util.*;
import java.io.*;
public class ho_t1 {
public static void main(String[] args) throws IOException{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new PrintStream(System.out));
int n=Integer.parseInt(f.readLine());
pair[]arr1=new pair[n+1];
StringTokenizer st=new StringTokenizer(f.readLine());
for(int i=0;i<=n;i++){
arr1[i]=new pair(Integer.parseInt(st.nextToken()),i);
}
st=new StringTokenizer(f.readLine());
pair[]arr2=new pair[n];
for(int i=0;i<n;i++){
arr2[i]=new pair(Integer.parseInt(st.nextToken()),i);
}
int ans[]=new int[n+1];
Arrays.sort(arr1);
Arrays.sort(arr2);
int[]ans1=new int[n];
int[]ans2=new int[n];
int[]prefix1=new int[n];
int[]prefix2=new int[n];
for(int i=0;i<n;i++){
ans1[i]=Math.max(0,arr1[i].num-arr2[i].num);
prefix1[i]=i==0?ans1[i]:Math.max(prefix1[i-1],ans1[i]);
ans2[i]=Math.max(0,arr1[i+1].num-arr2[i].num);
}
for(int i=n-1;i>=0;i--){
prefix2[i]=i==n-1?ans2[i]:Math.max(ans2[i],prefix2[i+1]);
}
for(int i=0;i<=n;i++){
if(i==0){
ans[arr1[i].idx]=prefix2[i];
}
if(i==n){
ans[arr1[i].idx]=prefix1[i-1];
}
if(i>0 && i<n){
ans[arr1[i].idx]=Math.max(prefix1[i-1],prefix2[i]);
}
}
out.print(ans[0]);
for(int i=1;i<=n;i++){
out.print(" "+ans[i]);
}
f.close();
out.close();
}
}
class pair implements Comparable <pair>{
int num;
int idx;
public int compareTo(pair other){
return num- other.num;
}
pair(int a, int b)
{
num=a;
idx=b;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
10268 KB |
Output is correct |
2 |
Correct |
74 ms |
10356 KB |
Output is correct |
3 |
Correct |
74 ms |
10360 KB |
Output is correct |
4 |
Correct |
76 ms |
10492 KB |
Output is correct |
5 |
Correct |
80 ms |
10636 KB |
Output is correct |
6 |
Correct |
79 ms |
10452 KB |
Output is correct |
7 |
Correct |
76 ms |
10220 KB |
Output is correct |
8 |
Correct |
79 ms |
10492 KB |
Output is correct |
9 |
Correct |
77 ms |
10388 KB |
Output is correct |
10 |
Correct |
83 ms |
10460 KB |
Output is correct |
11 |
Correct |
78 ms |
10488 KB |
Output is correct |
12 |
Correct |
75 ms |
10356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
10268 KB |
Output is correct |
2 |
Correct |
74 ms |
10356 KB |
Output is correct |
3 |
Correct |
74 ms |
10360 KB |
Output is correct |
4 |
Correct |
76 ms |
10492 KB |
Output is correct |
5 |
Correct |
80 ms |
10636 KB |
Output is correct |
6 |
Correct |
79 ms |
10452 KB |
Output is correct |
7 |
Correct |
76 ms |
10220 KB |
Output is correct |
8 |
Correct |
79 ms |
10492 KB |
Output is correct |
9 |
Correct |
77 ms |
10388 KB |
Output is correct |
10 |
Correct |
83 ms |
10460 KB |
Output is correct |
11 |
Correct |
78 ms |
10488 KB |
Output is correct |
12 |
Correct |
75 ms |
10356 KB |
Output is correct |
13 |
Correct |
85 ms |
10912 KB |
Output is correct |
14 |
Correct |
101 ms |
11580 KB |
Output is correct |
15 |
Correct |
126 ms |
12708 KB |
Output is correct |
16 |
Correct |
82 ms |
10508 KB |
Output is correct |
17 |
Correct |
130 ms |
12284 KB |
Output is correct |
18 |
Correct |
125 ms |
12296 KB |
Output is correct |
19 |
Correct |
125 ms |
12256 KB |
Output is correct |
20 |
Correct |
121 ms |
12632 KB |
Output is correct |
21 |
Correct |
128 ms |
12568 KB |
Output is correct |
22 |
Correct |
129 ms |
12484 KB |
Output is correct |
23 |
Correct |
123 ms |
12360 KB |
Output is correct |
24 |
Correct |
126 ms |
12560 KB |
Output is correct |
25 |
Correct |
128 ms |
12772 KB |
Output is correct |
26 |
Correct |
130 ms |
12792 KB |
Output is correct |
27 |
Correct |
132 ms |
12796 KB |
Output is correct |
28 |
Correct |
132 ms |
12428 KB |
Output is correct |
29 |
Correct |
131 ms |
12236 KB |
Output is correct |
30 |
Correct |
133 ms |
12616 KB |
Output is correct |
31 |
Correct |
120 ms |
12520 KB |
Output is correct |
32 |
Correct |
130 ms |
12536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
10268 KB |
Output is correct |
2 |
Correct |
74 ms |
10356 KB |
Output is correct |
3 |
Correct |
74 ms |
10360 KB |
Output is correct |
4 |
Correct |
76 ms |
10492 KB |
Output is correct |
5 |
Correct |
80 ms |
10636 KB |
Output is correct |
6 |
Correct |
79 ms |
10452 KB |
Output is correct |
7 |
Correct |
76 ms |
10220 KB |
Output is correct |
8 |
Correct |
79 ms |
10492 KB |
Output is correct |
9 |
Correct |
77 ms |
10388 KB |
Output is correct |
10 |
Correct |
83 ms |
10460 KB |
Output is correct |
11 |
Correct |
78 ms |
10488 KB |
Output is correct |
12 |
Correct |
75 ms |
10356 KB |
Output is correct |
13 |
Correct |
85 ms |
10912 KB |
Output is correct |
14 |
Correct |
101 ms |
11580 KB |
Output is correct |
15 |
Correct |
126 ms |
12708 KB |
Output is correct |
16 |
Correct |
82 ms |
10508 KB |
Output is correct |
17 |
Correct |
130 ms |
12284 KB |
Output is correct |
18 |
Correct |
125 ms |
12296 KB |
Output is correct |
19 |
Correct |
125 ms |
12256 KB |
Output is correct |
20 |
Correct |
121 ms |
12632 KB |
Output is correct |
21 |
Correct |
128 ms |
12568 KB |
Output is correct |
22 |
Correct |
129 ms |
12484 KB |
Output is correct |
23 |
Correct |
123 ms |
12360 KB |
Output is correct |
24 |
Correct |
126 ms |
12560 KB |
Output is correct |
25 |
Correct |
128 ms |
12772 KB |
Output is correct |
26 |
Correct |
130 ms |
12792 KB |
Output is correct |
27 |
Correct |
132 ms |
12796 KB |
Output is correct |
28 |
Correct |
132 ms |
12428 KB |
Output is correct |
29 |
Correct |
131 ms |
12236 KB |
Output is correct |
30 |
Correct |
133 ms |
12616 KB |
Output is correct |
31 |
Correct |
120 ms |
12520 KB |
Output is correct |
32 |
Correct |
130 ms |
12536 KB |
Output is correct |
33 |
Execution timed out |
1255 ms |
61604 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |