//####################
//Neckties
//####################
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define FLAG(x) cerr<<"FLAG("<<#x<<")";
typedef pair<int,int> pii;
const int INF = 1000*1000;
signed main(){
int n;cin>>n;
vector<int> bases(n);
vector<pii> neckties(n+1);
for(int i=0;i<=n;i++){
int v;cin>>v;
neckties[i] = make_pair(v,i);
}
for(int i=0;i<n;i++){cin>>bases[i];}
sort(bases.begin(),bases.end());
sort(neckties.begin(),neckties.end());
int Suffix[n+1];
int Prefix[n+1];
Suffix[n]=-INF;
Prefix[0]=-INF;
for(int i=n-1;i>=0;i--){
Suffix[i] = max(Suffix[i+1],max(neckties[i+1].first-bases[i],(long long)0));
}
for(int i=1;i<=n;i++){
Prefix[i] = max(Prefix[i-1],max(neckties[i-1].first-bases[i-1],(long long)0));
}
int ans[n+1];
for(int i=0;i<=n;i++){
ans[neckties[i].second] = max(Prefix[i],Suffix[i]);
}
for(int i=0;i<=n;i++){
cout<<ans[i]<<' ';
}
cout<<endl;
return 0;
};
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
440 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
440 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
444 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
432 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
508 KB |
Output is correct |
32 |
Correct |
2 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
440 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
444 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
432 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
508 KB |
Output is correct |
32 |
Correct |
2 ms |
448 KB |
Output is correct |
33 |
Correct |
146 ms |
14740 KB |
Output is correct |
34 |
Correct |
146 ms |
14972 KB |
Output is correct |
35 |
Correct |
143 ms |
14652 KB |
Output is correct |
36 |
Correct |
146 ms |
15324 KB |
Output is correct |
37 |
Correct |
148 ms |
15468 KB |
Output is correct |
38 |
Correct |
147 ms |
15280 KB |
Output is correct |
39 |
Correct |
150 ms |
14420 KB |
Output is correct |
40 |
Correct |
143 ms |
14164 KB |
Output is correct |
41 |
Correct |
143 ms |
14452 KB |
Output is correct |
42 |
Correct |
152 ms |
14416 KB |
Output is correct |
43 |
Correct |
143 ms |
14308 KB |
Output is correct |
44 |
Correct |
142 ms |
13904 KB |
Output is correct |
45 |
Correct |
142 ms |
14016 KB |
Output is correct |
46 |
Correct |
149 ms |
13952 KB |
Output is correct |
47 |
Correct |
142 ms |
14160 KB |
Output is correct |
48 |
Correct |
145 ms |
14200 KB |
Output is correct |
49 |
Correct |
148 ms |
14864 KB |
Output is correct |
50 |
Correct |
147 ms |
14672 KB |
Output is correct |
51 |
Correct |
156 ms |
14676 KB |
Output is correct |
52 |
Correct |
147 ms |
14676 KB |
Output is correct |
53 |
Correct |
150 ms |
14844 KB |
Output is correct |