Submission #916582

#TimeUsernameProblemLanguageResultExecution timeMemory
916582viwlesxqJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
87 ms16436 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 1e9 + 7;

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n; cin >> n;
    int a[n + 1], b[n];
    for (int i = 0; i <= n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    sort(b, b + n);
    vector<pair<int, int>> v;
    for (int i = 0; i <= n; ++i) v.push_back({a[i], i});
    int res[n + 1], suff[n + 1];
    sort(all(v));
    suff[n] = max(v[n].first - b[n - 1], 0ll);
    for (int i = n - 1; i > 0; --i) {
        suff[i] = max(suff[i + 1], max(v[i].first - b[i - 1], 0ll));
    }
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        res[v[i].second] = max(cur, suff[i + 1]);
        chmax(cur, max(v[i].first - b[i], 0ll));
    }
    res[v[n].second] = 0;
    for (int i = 0; i < n; ++i) {
        chmax(res[v[n].second], v[i].first - b[i]);
    }
    for (int i = 0; i <= n; ++i) cout << res[i] << ' ';
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...