#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<pair<int, int>> neckties(n+1);
for (int i=0;i<n+1;i++){
cin>>neckties[i].first;
neckties[i].second=i;
}
vector<int> employees(n);
for (int i=0;i<n;i++) cin>>employees[i];
sort(neckties.begin(), neckties.end(), greater<pair<int, int>>());
sort(employees.begin(), employees.end(), greater<int>());
vector<int> pref(n);
pref[0]=max(0, neckties[0].first-employees[0]);
for (int i=1;i<n;i++){
pref[i]=max(pref[i-1], max(0, neckties[i].first-employees[i]));
}
vector<int> suff(n);
suff[n-1]=max(0, neckties[n].first-employees[n-1]);
for (int i=n-2;i>=0;i--){
suff[i]=max(suff[i+1], max(0, neckties[i+1].first-employees[i]));
}
vector<int> out(n+1);
for (int i=0;i<n+1;i++){
int pr=0, sf=0;
if (i>0) pr=pref[i-1];
if (i<n) sf=suff[i];(
out[neckties[i].second]=max(pr, sf));
}
for (int x:out) cout<<x<<" ";
return 0;
}
Compilation message
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:35:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
35 | if (i<n) sf=suff[i];(
| ^~
ho_t1.cpp:35:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
35 | if (i<n) sf=suff[i];(
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 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 |
504 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 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 |
504 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 |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
472 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
516 KB |
Output is correct |
23 |
Correct |
1 ms |
512 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 |
504 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
2 ms |
516 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 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 |
504 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 |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
472 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
516 KB |
Output is correct |
23 |
Correct |
1 ms |
512 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 |
504 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
2 ms |
516 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
82 ms |
9800 KB |
Output is correct |
34 |
Correct |
74 ms |
10312 KB |
Output is correct |
35 |
Correct |
74 ms |
10056 KB |
Output is correct |
36 |
Correct |
74 ms |
10324 KB |
Output is correct |
37 |
Correct |
82 ms |
9956 KB |
Output is correct |
38 |
Correct |
73 ms |
10808 KB |
Output is correct |
39 |
Correct |
66 ms |
9544 KB |
Output is correct |
40 |
Correct |
66 ms |
9752 KB |
Output is correct |
41 |
Correct |
67 ms |
9784 KB |
Output is correct |
42 |
Correct |
68 ms |
8008 KB |
Output is correct |
43 |
Correct |
67 ms |
9544 KB |
Output is correct |
44 |
Correct |
72 ms |
9304 KB |
Output is correct |
45 |
Correct |
65 ms |
9556 KB |
Output is correct |
46 |
Correct |
67 ms |
9288 KB |
Output is correct |
47 |
Correct |
61 ms |
9448 KB |
Output is correct |
48 |
Correct |
64 ms |
9576 KB |
Output is correct |
49 |
Correct |
74 ms |
10056 KB |
Output is correct |
50 |
Correct |
79 ms |
8408 KB |
Output is correct |
51 |
Correct |
73 ms |
8520 KB |
Output is correct |
52 |
Correct |
71 ms |
10056 KB |
Output is correct |
53 |
Correct |
71 ms |
10056 KB |
Output is correct |