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 <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int b[MAXN], cuPrimul[MAXN], cuUltimul[MAXN], ans[MAXN];
struct A{
int a, pozInit;
};
A v[MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, i;
cin >> n;
for(i = 1; i <= n + 1; i++){
cin >> v[i].a;
v[i].pozInit = i;
}
for(i = 1; i <= n; i++){
cin >> b[i];
}
sort(v, v + n + 2, [](A e1, A e2){
return (e1.a < e2.a);
});
sort(b, b + n + 1);
// cuPrimul[i] = oddity of party until now (this vector includes the first element but excludes the last (a[i] - b[i])
for(i = 1; i <= n + 1; i++){
cuPrimul[i] = max(cuPrimul[i - 1], max(v[i].a - b[i], 0)); // oddity of party = maximum strangeness; strangeness = max{a − b, 0}
}
// cuUltimul[i] = oddity of party until now (this vector excludes the first element but includes the last (a[i + 1] - b[i])
for(i = n + 1; i >= 1; i--){
cuUltimul[i] = max(cuUltimul[i + 1], max(v[i + 1].a - b[i], 0));
}
for(i = 0; i <= n; i++){
ans[v[i + 1].pozInit] = max(cuPrimul[i], cuUltimul[i + 1]);
}
for(i = 1; i <= n + 1; i++){
cout << ans[i] << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |