#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
vector<pair<long long,long long> > a(n+2);
long long b[n+2];
for(long long i=1;i<=n+1;i++)
{
cin>>a[i].first;
a[i].second=i;
}
for(long long i=1;i<=n;i++)
cin>>b[i];
sort(a.begin(),a.end());
sort(b+1,b+n+1);
long long l[n+2],r[n+2];
for(long long i=1;i<=n;i++)
{
if(i==1)
l[i]=a[i].first-b[i];
else
l[i]=max(l[i-1],a[i].first-b[i]);
}
for(long long i=n+1;i>1;i--)
{
if(i==n+1)
r[i]=a[i].first-b[i-1];
else
r[i]=max(r[i+1],a[i].first-b[i-1]);
}
long long ans[n+2];
for(long long i=1;i<=n+1;i++)
{
long long j=a[i].second;
if(i==1)
ans[j]=r[i+1];
else
{
if(i==n+1)
ans[j]=l[i-1];
else
ans[j]=max(l[i-1],r[i+1]);
}
}
for(long long i=1;i<=n+1;i++)
cout<<max(ans[i],(long long)0)<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
376 KB |
Output is correct |
18 |
Correct |
7 ms |
380 KB |
Output is correct |
19 |
Correct |
7 ms |
376 KB |
Output is correct |
20 |
Correct |
7 ms |
376 KB |
Output is correct |
21 |
Correct |
7 ms |
376 KB |
Output is correct |
22 |
Correct |
8 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
7 ms |
376 KB |
Output is correct |
25 |
Correct |
8 ms |
376 KB |
Output is correct |
26 |
Correct |
9 ms |
504 KB |
Output is correct |
27 |
Correct |
7 ms |
376 KB |
Output is correct |
28 |
Correct |
7 ms |
376 KB |
Output is correct |
29 |
Correct |
7 ms |
372 KB |
Output is correct |
30 |
Correct |
7 ms |
376 KB |
Output is correct |
31 |
Correct |
7 ms |
376 KB |
Output is correct |
32 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
7 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
376 KB |
Output is correct |
18 |
Correct |
7 ms |
380 KB |
Output is correct |
19 |
Correct |
7 ms |
376 KB |
Output is correct |
20 |
Correct |
7 ms |
376 KB |
Output is correct |
21 |
Correct |
7 ms |
376 KB |
Output is correct |
22 |
Correct |
8 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
7 ms |
376 KB |
Output is correct |
25 |
Correct |
8 ms |
376 KB |
Output is correct |
26 |
Correct |
9 ms |
504 KB |
Output is correct |
27 |
Correct |
7 ms |
376 KB |
Output is correct |
28 |
Correct |
7 ms |
376 KB |
Output is correct |
29 |
Correct |
7 ms |
372 KB |
Output is correct |
30 |
Correct |
7 ms |
376 KB |
Output is correct |
31 |
Correct |
7 ms |
376 KB |
Output is correct |
32 |
Correct |
7 ms |
376 KB |
Output is correct |
33 |
Correct |
293 ms |
10848 KB |
Output is correct |
34 |
Correct |
310 ms |
11256 KB |
Output is correct |
35 |
Correct |
296 ms |
11000 KB |
Output is correct |
36 |
Correct |
301 ms |
11380 KB |
Output is correct |
37 |
Correct |
307 ms |
11640 KB |
Output is correct |
38 |
Correct |
301 ms |
11664 KB |
Output is correct |
39 |
Correct |
301 ms |
10616 KB |
Output is correct |
40 |
Correct |
310 ms |
10616 KB |
Output is correct |
41 |
Correct |
297 ms |
10616 KB |
Output is correct |
42 |
Correct |
304 ms |
10616 KB |
Output is correct |
43 |
Correct |
298 ms |
10616 KB |
Output is correct |
44 |
Correct |
297 ms |
10172 KB |
Output is correct |
45 |
Correct |
301 ms |
10232 KB |
Output is correct |
46 |
Correct |
308 ms |
10232 KB |
Output is correct |
47 |
Correct |
304 ms |
10232 KB |
Output is correct |
48 |
Correct |
304 ms |
10232 KB |
Output is correct |
49 |
Correct |
310 ms |
10872 KB |
Output is correct |
50 |
Correct |
310 ms |
10872 KB |
Output is correct |
51 |
Correct |
313 ms |
10872 KB |
Output is correct |
52 |
Correct |
309 ms |
10872 KB |
Output is correct |
53 |
Correct |
313 ms |
11000 KB |
Output is correct |