Cod sursa(job #825116)

Utilizator myrciu25Dunca Dohotar Mircea Ionut myrciu25 Data 27 noiembrie 2012 15:07:20
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
using namespace std;
#define INF 0x3f3f3f3f

ifstream is("secv2.in");
ofstream os("secv2.out");

int n, a[100], k;

int main()
{
    is >> n >> k;
    for ( int i = 0; i < n; i++)
        is >> a[i];

    int sc =  0, smax = -INF;
    int p1 = 0, p2 = 0, S, D, l = 1, lmax = 0;
    for ( int i = 0; i < n; i++)
    {
		sc += a[i];
		if (sc >= 0)
        {
			p2 = i;
			++l;
            if (sc > smax)
            {
				smax = sc;
				S = p1;
				D = p2;
			}
			if (l > lmax)
                lmax = l;
		}
		else
		{
			sc = 0;
			p1 = i + 1;
			l = 1;
        }
    }

    os << S+1 << ' ' << D+1 << ' ';
    if ( smax != -INF )
        os << smax;

    is.close();
    os.close();
    return 0;
}