# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051423 | manhlinh1501 | Just Long Neckties (JOI20_ho_t1) | C++17 | 65 ms | 10836 KiB |
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 pii = pair<int, int>;
using i64 = long long;
const int MAXN = 2e5 + 5;
int N;
pii a[MAXN];
int b[MAXN];
int prefix[MAXN];
int suffix[MAXN];
int ans[MAXN];
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N + 1; i++) {
cin >> a[i].first;
a[i].second = i;
}
for(int i = 1; i <= N; i++) cin >> b[i];
sort(a + 1, a + N + 2);
sort(b + 1, b + N + 1);
// for(int i = 1; i <= N + 1; i++) cout << a[i].first << " ";
for(int i = 1, j = 1; i <= N; i++) {
int x = a[j].first - b[i];
prefix[j] = max(prefix[j - 1], x);
j++;
}
for(int i = N, j = N + 1; i >= 1; i--) {
int x = a[j].first - b[i];
// cout << a[j].first << " " << b[i] << "\n";
suffix[j] = max(suffix[j + 1], x);
j--;
}
for(int i = 1; i <= N + 1; i++)
ans[a[i].second] = max(prefix[i - 1], suffix[i + 1]);
for(int i = 1; i <= N + 1; i++) cout << ans[i] << " ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |