Mai intai trebuie sa te autentifici.
Cod sursa(job #1416201)
Utilizator | Data | 7 aprilie 2015 16:56:25 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 15 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 1.39 kb |
#include <fstream>
#include <iostream>
//#include <cstring>
#define dimmax 21
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
bool numerepozitive=false;
int n;
int a[dimmax],best[dimmax],bestSum=0,i=0,auxpozibestSum;
int pozibestSum,pozsbestSum;
int main()
{
/*bool numerepozitive=false;
int n;
int a[dimmax],best[dimmax],bestSum=0,i=0,auxpozibestSum;
int pozibestSum,pozsbestSum;*/
fin>>n;
//memset(best,0,sizeof(best));
//memset(a,0,sizeof(a));
for(i=0;i<=n;i++)
{
fin>>a[i];
if(a[i]>0)
numerepozitive=true;
}
bestSum=a[0];
pozibestSum=0;pozsbestSum=0;
// fout<<best[i]<<' ';
for(i=0;i<n;i++)
{
best[i]=a[i];
if (best[i]<best[i-1]+a[i])
{
best[i]=best[i-1]+a[i];
// fout<<best[i]<<' ';
}
if(best[i-1]<0 and numerepozitive==true)
{
/* pozicrt=i;*/
pozibestSum=i;
}
if (bestSum<best[i])
{
bestSum=best[i];
pozsbestSum=i;
if(best[i-1]<0 and numerepozitive==false)
{
/* pozicrt=i;*/
pozibestSum=i;
}
}
}
fout<<bestSum<<' '<<pozibestSum+1<<' '<<pozsbestSum+1;
fin.close(); fout.close();
return 0;
}