제출 #203641

#제출 시각아이디문제언어결과실행 시간메모리
203641osaaateiasavtnlJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
141 ms11768 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7;
ii a[N];
int b[N], mem[N], pref[N], post[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i].f;
        a[i].s = i;
    }
    for (int i = 0; i < n; ++i) 
        cin >> b[i];
 
    sort(a, a + n + 1);
    sort(b, b + n);
 
    for (int i = 0; i < n; ++i)
        pref[i + 1] = max(pref[i], a[i].f - b[i]);
    for (int i = n - 1; i >= 0; --i)
        post[i] = max(post[i + 1], a[i + 1].f - b[i]);
 
    for (int i = 0; i < n + 1; ++i) 
        mem[a[i].s] = max(pref[i], post[i]);
     
    for (int i = 0; i <= n; ++i)
        cout << mem[i] << ' ';
    cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...