Pagini recente » Cod sursa (job #650187) | Cod sursa (job #3157360) | Cod sursa (job #1477927) | Cod sursa (job #2283226) | Cod sursa (job #664376)
Cod sursa(job #664376)
#include <fstream>
using namespace std;
int max1,i,n,a[6000000],suma[6000000],poz;
bool ok;
int maxim (int x, int y)
{
if (x>y) return x;
else return y;
}
int main ()
{
ifstream f ("ssm.in");
ofstream g ("ssm.out");
f >>n;
for (i=1; i<=n; i++)
f >>a[i];
for (i=1; i<=n; i++)
suma[i]=maxim (suma[i-1]+a[i] , a[i]);
max1=0;
for (i=1; i<=n; i++)
if (max1<suma[i]) max1=suma[i],poz=i;
i=poz;
ok=true;
while (i>0)
{
if (suma[i]<=0) {g <<max1<<' '<<i+1 <<' '<<poz; ok=false;}
i--;
}
if (ok) g <<max1<<' '<<1 <<' '<<poz;
return 0;
}