Cod sursa(job #1199880)
| Utilizator | Data | 20 iunie 2014 23:33:07 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
int N, a[6000010],best[6000010];
int main(){
ifstream in("ssm.in");
ofstream out("ssm.out");
in >> N;
int i, MAX=-(1<<30),x,y;
for (i=1; i<=N; i++) in >> a[i];
for (i=1; i<=N; i++) { best[i]=max(a[i],a[i]+best[i-1]); if (best[i]>MAX) MAX=best[i]; }
for (i=1; i<=N; i++) if (best[i]==MAX) { x = y = i; while (best[x]==best[x-1] + a[x]) x--; }
out << MAX << " " << x << " " << y;
}
