Submission #1110233

#TimeUsernameProblemLanguageResultExecution timeMemory
1110233vjudge1Growing Vegetables is Fun 5 (JOI24_vegetables5)C++17
9 / 100
5073 ms29120 KiB
#include<bits/stdc++.h> #define fi first #define se second #define ll long long #define pb push_back using namespace std; ll n,a[600005],b[600005],c[600005]; int getb(int l,int r) { vector<int> vb,vc; for(int i=1;i<l;i++) vc.pb(a[i]); for(int i=l;i<=r;i++) vb.pb(a[i]); for(int i=r+1;i<=2*n;i++) vc.pb(a[i]); sort(vc.begin(),vc.end()); sort(vb.begin(),vb.end()); ll mx=0; for(int i=1;i<=n;i++) { mx=max(mx,abs(b[i]-vb[i-1])); } for(int i=1;i<=n;i++) { mx=max(mx,abs(c[i]-vc[i-1])); } return mx; } int getc(int l,int r) { vector<int> vb,vc; for(int i=1;i<l;i++) vb.pb(a[i]); for(int i=l;i<=r;i++) vc.pb(a[i]); for(int i=r+1;i<=2*n;i++) vb.pb(a[i]); sort(vc.begin(),vc.end()); sort(vb.begin(),vb.end()); ll mx=0; for(int i=1;i<=n;i++) { mx=max(mx,abs(b[i]-vb[i-1])); } for(int i=1;i<=n;i++) { mx=max(mx,abs(c[i]-vc[i-1])); } return mx; } bool check(int mid) { for(int i=1;i<=n+1;i++) { int mx=0; mx=getb(i,i+n-1); if(mx<=mid) return true; mx=getc(i,i+n-1); if(mx<=mid) return true; } return false; } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); // freopen(".INP","r",stdin); // freopen(".OUT","w",stdout); cin>>n; for(int i=1;i<=n*2;i++) { cin>>a[i]; } for(int i=1;i<=n;i++) { cin>>b[i]; } for(int i=1;i<=n;i++) { cin>>c[i]; } sort(b+1,b+1+n); sort(c+1,c+1+n); int l=0,r=1e9,res=0; while(l<=r) { int mid=(l+r)/2; if(check(mid)) { res=mid; r=mid-1; } else l=mid+1; } cout<<res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...