Submission #958264

#TimeUsernameProblemLanguageResultExecution timeMemory
958264MilosMilutinovic도넛 (JOI14_ho_t3)C++14
100 / 100
93 ms3156 KiB
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;} template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;} ll readint(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n; int a[100005],nxt[100005]; ll pref[100005]; ll get(int l,int r){ if(l<=r) return pref[r]-pref[l-1]; else return pref[n]-(pref[l-1]-pref[r]); } bool check(ll x){ if(pref[n]<x) return false; int ptr=1; for(int i=1;i<=n;i++){ while(get(i,ptr)<x) ptr=(ptr%n)+1; nxt[i]=ptr; if(ptr==i) ptr=(ptr%n)+1; } for(int i=1;i<=n;i++){ ll a=get(i,nxt[i]); ll b=get((nxt[i]%n)+1,nxt[(nxt[i]%n)+1]); ll c=get(nxt[(nxt[i]%n)+1]%n+1,nxt[nxt[(nxt[i]%n)+1]%n+1]); if(a+b+c<=pref[n]) return true; } return false; } int main(){ n=readint(); for(int i=1;i<=n;i++) a[i]=readint(); for(int i=1;i<=n;i++) pref[i]=pref[i-1]+a[i]; ll l=0,r=1e17,ans=0; while(l<=r){ ll mid=(l+r)/2; if(check(mid)) ans=mid,l=mid+1; else r=mid-1; } printf("%lld\n",ans); 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...