#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> a(n+1);
vector<int> b(n);
vector<int> c(n+1);
for(int i = 0;i<n+1;i++)
{
cin>>a[i];
c[i] = a[i];
}
for(int i = 0;i<n;i++)
{
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
long long su[n];
su[0] = max(a[0]-b[0],0);
for(int i = 1;i<n;i++)
{
su[i] = max(su[i-1],(long long)max(a[i]-b[i],0));
}
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
long long pr[n];
pr[0] = max(a[0] - b[0],0);
for(int i = 1;i<n;i++)
{
pr[i] = max(pr[i-1],(long long)max(a[i]-b[i],0));
}
unordered_map<int,long long> ans;
ans[a[0]] = su[n-1];
for(int i = 1;i<n;i++)
{
ans[a[i]] = max(pr[i-1], su[n-i-1]);
}
ans[a[n]] = pr[n-1];
for(int i = 0;i<n+1;i++)
{
cout<<ans[c[i]]<<" ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
452 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
476 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
452 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
476 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
592 KB |
Output is correct |
33 |
Correct |
164 ms |
15732 KB |
Output is correct |
34 |
Correct |
169 ms |
16368 KB |
Output is correct |
35 |
Correct |
174 ms |
18804 KB |
Output is correct |
36 |
Correct |
170 ms |
18456 KB |
Output is correct |
37 |
Correct |
170 ms |
16756 KB |
Output is correct |
38 |
Correct |
180 ms |
16628 KB |
Output is correct |
39 |
Correct |
178 ms |
17784 KB |
Output is correct |
40 |
Correct |
171 ms |
15556 KB |
Output is correct |
41 |
Correct |
177 ms |
15840 KB |
Output is correct |
42 |
Correct |
191 ms |
18044 KB |
Output is correct |
43 |
Correct |
184 ms |
17524 KB |
Output is correct |
44 |
Correct |
174 ms |
15268 KB |
Output is correct |
45 |
Correct |
176 ms |
18320 KB |
Output is correct |
46 |
Correct |
172 ms |
15216 KB |
Output is correct |
47 |
Correct |
129 ms |
7996 KB |
Output is correct |
48 |
Correct |
151 ms |
11208 KB |
Output is correct |
49 |
Correct |
202 ms |
16756 KB |
Output is correct |
50 |
Correct |
188 ms |
19316 KB |
Output is correct |
51 |
Correct |
182 ms |
16000 KB |
Output is correct |
52 |
Correct |
181 ms |
19320 KB |
Output is correct |
53 |
Correct |
175 ms |
15888 KB |
Output is correct |