Cod sursa(job #140590)
Utilizator | Data | 21 februarie 2008 23:47:25 | |
---|---|---|---|
Problema | Secventa 2 | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.4 kb |
#include<fstream.h>
main()
{
ifstream fi("secv2.in");ofstream fo("secv2.out");
long s,n,k,m_p,m_d,max=0;
int v[50000],i,j,h;
fi>>n>>k;
for(i=1;i<=n;i++){fi>>v[i];max+=v[i];}
m_p=1;
m_d=n;
for(i=k;i<n;i++)
for(j=1;j<n-i;j++)
{
s=0;
for(h=j;h<=j+i;h++)s+=v[h];
if(s>max)
{
max=s;
m_p=j;
m_d=i;
}
}
fo<<m_p<<" "<<m_p+m_d<<" "<<max;
}