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;
using ll = long long;
using ii = pair<int, int>;
const int maxn = 2e5 + 5;
int n;
int a[maxn], b[maxn], p[maxn], s[maxn];
int ord[maxn], ans[maxn];
int main(int argc, char const *argv[])
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
cin >> n;
for(int i = 1; i <= n+1; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
cin >> b[i];
}
iota(ord + 1, ord + 2 + n, 1);
sort(ord + 1, ord + 2 + n, [](int i, int j){
return a[i] < a[j];
});
sort(a + 1, a + 2 + n);
sort(b + 1, b + 1 + n);
for(int i = n+1; i > 1; i--) {
s[i] = max(s[i+1], a[i] - b[i-1]);
}
for(int i = 1; i <= n; i++) {
p[i] = max(p[i-1], a[i] - b[i]);
}
for(int i = 1; i <= n+1; i++) {
// cout << max(p[i-1], s[i+1]) << ' ';
ans[ord[i]] = max(p[i-1], s[i+1]);
}
for(int i = 1; i <= n+1; i++) cout << ans[i] << ' '; cout << endl;
return 0;
}
Compilation message (stderr)
ho_t1.cpp: In function 'int main(int, const char**)':
ho_t1.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int i = 1; i <= n+1; i++) cout << ans[i] << ' '; cout << endl;
^~~
ho_t1.cpp:41:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(int i = 1; i <= n+1; i++) cout << ans[i] << ' '; cout << endl;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |