이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
void dout() { cerr << '\n'; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << " " << H;
dout(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
#define dbg(...) ;
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 2e5 + 123;
int n, a[N], b[N], suf[N], ans[N];
pii A[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin >> n;
for (int i = 1; i <= n + 1; i++) {
cin >> a[i];
A[i] = {a[i], i};
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
sort(b + 1, b + n + 1);
sort(A + 1, A + n + 2);
suf[n + 2] = 0;
for (int i = n + 1; i >= 2; i--) {
suf[i] = max(suf[i + 1], A[i].fi - b[i - 1]);
}
int pref = 0;
for (int i = 1; i <= n + 1; i++) {
ans[A[i].se] = max(pref, suf[i + 1]);
if (i == n + 1) {
break;
}
pref = max(pref, A[i].fi - b[i]);
}
for (int i = 1; i <= n + 1; i++) {
cout << ans[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... |