Pagini recente » Cod sursa (job #1775617) | Cod sursa (job #358866) | Cod sursa (job #1883472) | Cod sursa (job #2377754) | Cod sursa (job #602825)
Cod sursa(job #602825)
#include <fstream>
using namespace std;
int a[50001],b[50001],c[50001],n,k;
char buf1[50001];
int main(void){
int i,j,max,pozmax,lmax;
bool bo=false;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
fin>>n>>k;
for(i=1;i<=n;++i)fin>>a[i]; fin.close();
b[n]=a[n]; c[n]=1;
for(i=n-1;i>=1;--i){
max=a[i]; c[i]=1; bo=false;
for(j=n;j>=i+1;--j)
if(max+b[j]>a[i]){
max=b[j];
c[i]=c[j]+1;
bo=true;
}
if (!bo) b[i]=a[i]; else b[i]=a[i]+max;
}
max=-25001; pozmax=0; lmax=0;
for(i=n;i>=1;--i)
if(b[i]>max)
if(c[i]>=lmax)
{
max=b[i]; pozmax=i; lmax=c[i];
}
fout<<pozmax<<" "<<pozmax+lmax-1<<" "<<max;
fout.close();
return 0;
}