#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
map<ll,int> s;
void add(ll num){
s[num]++;
}
void remove(ll num){
s[num]--;
if(s[num]==0) s.erase(num);
}
ll getmax(){
return s.rbegin()->first;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
ll a[n+1]={0};
for(int i=0;i<n+1;i++){
cin>>a[i];
}
ll b[n];
for(int i=0;i<n;i++) cin>>b[i];
sort(b,b+n);
int order[n+1];
for(int i=0;i<=n;i++) order[i]=i;
sort(order,order+n+1,[&](const int x,const int y){return a[x]<a[y];});
ll c[n+1]={0};
for(int i=n;i>=1;i--){
add(max(a[order[i]]-b[i-1],0LL));
}
c[order[0]] = getmax();
for(int k=1;k<=n;k++){
remove(max(a[order[k]]-b[k-1],0LL));
add(max(a[order[k-1]]-b[k-1],0LL));
c[order[k]]=getmax();
}
for(int i=0;i<=n;i++) cout<<c[i]<<" ";
cout<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
151 ms |
18256 KB |
Output is correct |
34 |
Correct |
194 ms |
22204 KB |
Output is correct |
35 |
Correct |
135 ms |
16976 KB |
Output is correct |
36 |
Correct |
191 ms |
22640 KB |
Output is correct |
37 |
Correct |
195 ms |
23380 KB |
Output is correct |
38 |
Correct |
192 ms |
23204 KB |
Output is correct |
39 |
Correct |
139 ms |
11856 KB |
Output is correct |
40 |
Correct |
138 ms |
11684 KB |
Output is correct |
41 |
Correct |
138 ms |
11856 KB |
Output is correct |
42 |
Correct |
163 ms |
11872 KB |
Output is correct |
43 |
Correct |
136 ms |
11856 KB |
Output is correct |
44 |
Correct |
87 ms |
10576 KB |
Output is correct |
45 |
Correct |
90 ms |
10320 KB |
Output is correct |
46 |
Correct |
85 ms |
10436 KB |
Output is correct |
47 |
Correct |
75 ms |
12756 KB |
Output is correct |
48 |
Correct |
72 ms |
12852 KB |
Output is correct |
49 |
Correct |
145 ms |
12088 KB |
Output is correct |
50 |
Correct |
145 ms |
12224 KB |
Output is correct |
51 |
Correct |
138 ms |
12068 KB |
Output is correct |
52 |
Correct |
159 ms |
12116 KB |
Output is correct |
53 |
Correct |
140 ms |
12112 KB |
Output is correct |