#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define X first
#define Y second
int n,m,a[200005],b[200005],ti[200005],chng[200005],idx[200005],l[200005],r[200005];
vector<int> v;
vector<pair<int,int> > p;
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n;
for(int i=1;i<=n+1;i++)cin >> a[i];
for(int i=1;i<=n;i++)cin >> b[i];
for(int i=1;i<=n;i++)
{
v.pb(b[i]);
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)ti[i+1]=v[i];
for(int i=1;i<=n+1;i++)
{
p.pb({a[i],i});
}
sort(p.begin(),p.end());
for(int i=0;i<p.size();i++)
{
idx[p[i].second]=i+1;
chng[i+1]=p[i].X;
}
l[1]=max(-ti[1]+chng[1],0);
for(int i=2;i<=n;i++)
{
l[i]=max(l[i-1],max(-ti[i]+chng[i],0));
}
r[n+1]=max(-ti[n]+chng[n+1],0);
for(int i=n;i>=2;i--)
{
r[i]=max(r[i+1],max(-ti[i-1]+chng[i],0));
}
/*printf("l\n");
for(int i=1;i<=n;i++)
{
printf("%d ",l[i]);
}
printf("\n");
printf("r\n");
for(int i=2;i<=n+1;i++)
{
printf("%d ",r[i]);
}
printf("\n");*/
for(int i=1;i<=n+1;i++)
{
printf("%d ",max(l[idx[i]-1],r[idx[i]+1]));
}
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<v.size();i++)ti[i+1]=v[i];
| ~^~~~~~~~~
ho_t1.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<p.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
268 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
268 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
472 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
496 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
268 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
472 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
496 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
87 ms |
13120 KB |
Output is correct |
34 |
Correct |
96 ms |
13588 KB |
Output is correct |
35 |
Correct |
90 ms |
13200 KB |
Output is correct |
36 |
Correct |
92 ms |
13684 KB |
Output is correct |
37 |
Correct |
92 ms |
14104 KB |
Output is correct |
38 |
Correct |
91 ms |
13972 KB |
Output is correct |
39 |
Correct |
87 ms |
12992 KB |
Output is correct |
40 |
Correct |
91 ms |
12872 KB |
Output is correct |
41 |
Correct |
90 ms |
13084 KB |
Output is correct |
42 |
Correct |
92 ms |
12972 KB |
Output is correct |
43 |
Correct |
88 ms |
12888 KB |
Output is correct |
44 |
Correct |
86 ms |
12424 KB |
Output is correct |
45 |
Correct |
86 ms |
12572 KB |
Output is correct |
46 |
Correct |
88 ms |
12460 KB |
Output is correct |
47 |
Correct |
88 ms |
12672 KB |
Output is correct |
48 |
Correct |
83 ms |
12656 KB |
Output is correct |
49 |
Correct |
93 ms |
13252 KB |
Output is correct |
50 |
Correct |
91 ms |
13292 KB |
Output is correct |
51 |
Correct |
96 ms |
13408 KB |
Output is correct |
52 |
Correct |
90 ms |
13256 KB |
Output is correct |
53 |
Correct |
90 ms |
13236 KB |
Output is correct |