Submission #208974

#TimeUsernameProblemLanguageResultExecution timeMemory
208974AQTJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
128 ms11768 KiB
#include <bits/stdc++.h> using namespace std; int N; int arr[200005]; pair<long long, int> srt[200005]; int brr[200005]; long long ans[200005]; long long pre[200005], suf[200005]; int main(){ cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1; i<=N+1; i++){ cin >> arr[i]; srt[i] = {arr[i], i}; } sort(srt+1, srt+2+N); for(int i = 1; i<=N; i++){ cin >> brr[i]; } sort(brr+1, brr+1+N); for(int i= 1; i<=N+1; i++){ pre[i] = pre[i-1]; pre[i] = max(pre[i], srt[i].first - brr[i]); } for(int i = N+1; i; i--){ suf[i] = suf[i+1]; suf[i] = max(suf[i], srt[i].first - brr[i-1]); } for(int i = 1; i<=N+1; i++){ int idx = srt[i].second; ans[idx] = max(pre[i-1], suf[i+1]); } for(int i =1 ; i<=N+1; i++){ cout << ans[i] << " "; } cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...