#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n;
cin>>n;
llo ac;
vector<pair<llo,llo>> aa;
vector<pair<llo,llo>> bb;
for(llo i=0;i<n+1;i++){
cin>>ac;
aa.pb({ac,i});
}
for(llo j=0;j<n;j++){
cin>>ac;
bb.pb({ac,j});
}
sort(aa.begin(),aa.end());
sort(bb.begin(),bb.end());
llo ans[n];
multiset<llo,std::greater<llo>> cc;
for(llo i=0;i<n;i++){
ans[i]=aa[i].a-bb[i].a;
cc.insert(ans[i]);
}
llo ans2[n];
ans2[aa[n].b]=max(*(cc.begin()),(llo)0);
for(llo i=n-1;i>=0;i--){
auto it=cc.find(ans[i]);
cc.erase(it);
ans[i]=aa[i+1].a-aa[i].a+ans[i];
cc.insert(ans[i]);
// cout<<i<<" "<<ans[i]<<endl;
ans2[aa[i].b]=max(*(cc.begin()),(llo)0);
}
for(llo i=0;i<n+1;i++){
cout<<ans2[i]<<" ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
640 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
6 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
512 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
7 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
0 ms |
512 KB |
Output is correct |
30 |
Correct |
7 ms |
512 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
7 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
6 ms |
640 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
6 ms |
512 KB |
Output is correct |
20 |
Correct |
6 ms |
512 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
6 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
512 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
7 ms |
512 KB |
Output is correct |
27 |
Correct |
6 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
0 ms |
512 KB |
Output is correct |
30 |
Correct |
7 ms |
512 KB |
Output is correct |
31 |
Correct |
7 ms |
512 KB |
Output is correct |
32 |
Correct |
7 ms |
612 KB |
Output is correct |
33 |
Correct |
287 ms |
23512 KB |
Output is correct |
34 |
Correct |
302 ms |
24408 KB |
Output is correct |
35 |
Correct |
243 ms |
23896 KB |
Output is correct |
36 |
Correct |
244 ms |
24152 KB |
Output is correct |
37 |
Correct |
256 ms |
24920 KB |
Output is correct |
38 |
Correct |
243 ms |
24668 KB |
Output is correct |
39 |
Correct |
272 ms |
23512 KB |
Output is correct |
40 |
Correct |
262 ms |
23512 KB |
Output is correct |
41 |
Correct |
287 ms |
23640 KB |
Output is correct |
42 |
Correct |
275 ms |
23644 KB |
Output is correct |
43 |
Correct |
291 ms |
23512 KB |
Output is correct |
44 |
Correct |
269 ms |
22876 KB |
Output is correct |
45 |
Correct |
269 ms |
23004 KB |
Output is correct |
46 |
Correct |
273 ms |
22872 KB |
Output is correct |
47 |
Correct |
201 ms |
23640 KB |
Output is correct |
48 |
Correct |
233 ms |
23644 KB |
Output is correct |
49 |
Correct |
276 ms |
24156 KB |
Output is correct |
50 |
Correct |
273 ms |
24152 KB |
Output is correct |
51 |
Correct |
276 ms |
24152 KB |
Output is correct |
52 |
Correct |
277 ms |
24152 KB |
Output is correct |
53 |
Correct |
299 ms |
24280 KB |
Output is correct |