Submission #224011

#TimeUsernameProblemLanguageResultExecution timeMemory
224011dwscJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
503 ms21880 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
main(){
    int n;
    cin >> n;
    ii arr[n+1];
    for (int i = 0; i < n+1; i++) {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    int arr2[n];
    for (int i = 0; i < n; i++) cin >> arr2[i];
    sort(arr,arr+n+1);
    sort(arr2,arr2+n);
    int ans[n+1];
    ans[n] = 0;
    multiset<int> s;
    for (int i = 0; i < n; i++) s.insert(max(arr[i].first-arr2[i],0LL));
    ans[arr[n].second] = *(--s.end());
    for (int i = n-1; i >= 0; i--){
        s.erase(s.find(max(arr[i].first-arr2[i],0LL)));
        s.insert(max(arr[i+1].first-arr2[i],0LL));
        ans[arr[i].second] = *(--s.end());
    }
    for (int i = 0; i < n+1; i++) cout << ans[i] << " ";
}

Compilation message (stderr)

ho_t1.cpp:5:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...