This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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];(
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |