Submission #502770

#TimeUsernameProblemLanguageResultExecution timeMemory
502770TheTrapperJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
105 ms15468 KiB
#include <bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; using pll=pair<ll,ll>; using vll=vector<ll>; using vpl=vector<pll>; using vstr=vector<string>; using sll=set<ll>; using spl=set<pll>; ll INF=1e18; #define PI 3.14159265 ll MOD=1e9+7; pll ntie[200005]; ll employ[200005]; ll beforeceo[200005]; ll afterceo[200005]; ll result[200005]; bool Compare(pll p,pll q) { return p.first<q.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n=0; cin >> n; for(ll i=1;i<=n+1;i++) { pll neck; cin >> neck.first; neck.second=i; ntie[i]=neck; } for(ll i=1;i<=n;i++) { cin >> employ[i]; } sort(ntie+1,ntie+n+2,Compare); sort(employ+1,employ+n+1); beforeceo[0]=0; for(ll i=1;i<=n+1;i++) { beforeceo[i]=max(beforeceo[i-1],max(ntie[i].first-employ[i],0LL)); } afterceo[0]=0; for(ll i=n;i>=1;i--) { afterceo[i]=max(afterceo[i+1],max(ntie[i+1].first-employ[i],0LL)); } for(ll i=1;i<=n+1;i++) { ll ceo=ntie[i].second; ll ans=max(beforeceo[i-1],afterceo[i]); //cout << "DEBUG " << beforeceo[i-1] << " " << afterceo[i] << '\n'; result[ceo]=ans; } for(ll i=1;i<=n+1;i++) { cout << result[i] << " "; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...