제출 #757072

#제출 시각아이디문제언어결과실행 시간메모리
757072michaoJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
111 ms18752 KiB
#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=2e5+5; int a[MAX]; int b[MAX]; int maxpref[MAX],maxsuf[MAX]; int ans[MAX]; int c[MAX]; bool cmp(int i,int j){ return a[i]<a[j]; } int32_t main() { BOOST; int n; cin>>n; for (int i=1;i<=n+1;i++)cin>>a[i]; for (int i=1;i<=n;i++)cin>>b[i]; sort(b+1,b+n+1); for (int i=1;i<=n+1;i++)c[i]=i; sort(c+1,c+n+2,cmp); vi c1,c2; for (int i=1;i<=n;i++)c2.pb(b[i]); for (int i=1;i<=n;i++)c1.pb(a[i]); for (int i=1;i<=n;i++){ int id=c[i]; maxpref[i]=max(maxpref[i-1],a[id]-b[i]); } for (int i=n;i>=1;i--){ int id=c[i+1]; //cout<<"XD "<<id<<" "<<i<<"\n"; maxsuf[i]=max(maxsuf[i+1],a[id]-b[i]); //cout<<"AFTER "<<i<<" "<<maxsuf[i]<<"\n"; } for (int wywal=1;wywal<=n+1;wywal++){ int ilebiore=n-(wywal-1); ans[c[wywal]]=max(maxpref[wywal-1],maxsuf[n-ilebiore+1]); } for (int i=1;i<=n+1;i++)cout<<ans[i]<<" "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...