Pagini recente » Statistici Serba Raluca (imnofuxkingfun) | Statistici george (altaugeorge) | Monitorul de evaluare | police | Cod sursa (job #2208266)
#include<iostream>
#include<algorithm>
#include<fstream>
using namespace std;
ifstream fin("transport.in");
ofstream gout("transport.out");
long long s[16001],v[16001];
int main(){
long long N,K,i,x,max,max1,u,g,w,y,v,z,st,dr,pp,e,f,m;
fin>>N;
fin>>K;
max=0;
for(i=1;i<=N;i++){
fin>>x;
if (x>max)
max=x;
s[i]=s[i-1]+x;
}
u=0;
for(g=N;g>=1;g--){
w=N-g+1;
for(y=1;y<=g;y++)
if (s[y]-s[w]>=max){
u++;
v[u]=s[y]-s[w];
}
}
sort(v+1,v+1+u);
z=max;
st=1;
dr=u;
pp=0;
e=max+1;
f=0;
max1=max;
while (z<u&&f<=g){
while (st<=dr&&pp==0&&z<u){
m=(st+dr)/2;
if (v[m]==e)
pp=m;
else if (e<v[m])
dr=m-1;
else st=m+1;
}
if (pp!=0){
z=z+v[m];
f++;
if (v[m]>max1)
max1=v[m];
}
e++;
}
gout<<max1;
return 0;
}