제출 #520911

#제출 시각아이디문제언어결과실행 시간메모리
520911AdamGSJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
88 ms15556 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=2e5+7; pair<ll,int>A[LIM]; ll B[LIM], pref[LIM], suf[LIM], ans[LIM]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rep(i, n+1) { cin >> A[i].st; A[i].nd=i; } rep(i, n) cin >> B[i]; sort(A, A+n+1); sort(B, B+n); rep(i, n) { if(i) pref[i]=pref[i-1]; pref[i]=max(pref[i], max(A[i].st-B[i], 0ll)); } for(int i=n-1; i>=0; --i) { suf[i]=suf[i+1]; suf[i]=max(suf[i], max(A[i+1].st-B[i], 0ll)); } ans[A[0].nd]=suf[0]; ans[A[n].nd]=pref[n-1]; for(int i=1; i<n; ++i) { ans[A[i].nd]=max(pref[i-1], suf[i]); } rep(i, n+1) cout << ans[i] << " "; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...