Cod sursa(job #1669079)
Utilizator | Andreea Patarlageanu APatarlageanu | Data | 30 martie 2016 12:36:47 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
#include <iostream>
#define INF 2000000000
using namespace std;
ifstream in ( "ssm.in" );
ofstream out ( "ssm.out" );
int main()
{
int n, smax, sc, i, pc, pmax, umax, x;
in>>n;
smax = -INF;
sc = -1;
for ( i = 1; i <= n; i++ ) {
in>>x;
if ( sc < 0 ) {
sc = 0;
pc = i;
}
sc = sc + x;
if ( sc > smax ) {
smax = sc;
pmax = pc;
umax = i;
}
}
out<<smax<<" "<<pmax<<" "<<umax;
return 0;
}