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>
#define LL long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using namespace std;
const int nax = 2e5 + 111;
int n;
pair<int,int> a[nax];
int b[nax];
int s[nax][2];
int ans[nax];
int main() {
scanf ("%d", &n);
rep(i, 1, n + 1) {
scanf ("%d", &a[i].fi);
a[i].se = i;
}
rep(i, 1, n) scanf ("%d", b + i);
sort(b + 1, b + n + 1);
sort(a + 1, a + n + 2);
rep(i, 1, n) {
s[i][0] = max(0, a[i].fi - b[i]);
s[i][1] = max(0, a[i + 1].fi - b[i]);
}
rep(i, 1, n) s[i][0] = max(s[i][0], s[i - 1][0]);
per(i, 1, n) s[i][1] = max(s[i][1], s[i + 1][1]);
rep(i, 1, n + 1) {
// printf ("%d %d %d\n", i, s[i - 1][0], s[i][1]);
int x = (i > 0 ? s[i - 1][0] : 0);
x = max(x, s[i][1]);
ans[a[i].se] = x;
}
rep(i, 1, n + 1) printf ("%d ", ans[i]);
return 0;
}
Compilation message (stderr)
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &n);
~~~~~~^~~~~~~~~~
ho_t1.cpp:25:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &a[i].fi);
~~~~~~^~~~~~~~~~~~~~~~
ho_t1.cpp:28:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
rep(i, 1, n) scanf ("%d", b + 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... |