import sys readline=sys.stdin.readline class Path_Doubling: def __init__(self,N,permutation,lst=None,f=None,e=None): self.N=N self.permutation=permutation self.lst=lst self.f=f self.e=e def Build_Next(self,K=None): if K==None: K=self.N self.k=K.bit_length() self.permutation_doubling=[[self.permutation[n]] for n in range(self.N)] if self.lst!=None: self.doubling=[[self.lst[n]] for n in range(self.N)] for k in range(1,self.k): for n in range(self.N): if self.permutation_doubling[n][k-1]==None: self.permutation_doubling[n].append(None) if self.f!=None: self.doubling[n].append(None) if self.permutation_doubling[n][k-1]!=None: self.permutation_doubling[n].append(self.permutation_doubling[self.permutation_doubling[n][k-1]][k-1]) if self.f!=None: self.doubling[n].append(self.f(self.doubling[n][k-1],self.doubling[self.permutation_doubling[n][k-1]][k-1])) def Permutation_Doubling(self,N,K): if K<0 or 1<>k&1 and N!=None: N=self.permutation_doubling[N][k] return N def Doubling(self,N,K): if K<0: return self.e retu=self.e for k in range(self.k): if K>>k&1: if self.permutation_doubling[N][k]==None: return None retu=self.f(retu,self.doubling[N][k]) N=self.permutation_doubling[N][k] return retu def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok N,K=map(int,readline().split()) A=list(map(int,readline().split())) sum_A=sum(A) A=[0]+A*2 for i in range(1,2*N+1): A[i]+=A[i-1] def is_ok(ans): perm=[i for i in range(2*N+1)] r=0 for l in range(2*N): while r<2*N and A[r]-A[l]