Cod sursa(job #2427954)
| Utilizator | Data | 3 iunie 2019 09:22:47 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 15 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, a[101], s, smax = -2000000000, poz1, poz2;
int main(){
fin>>n;
for(int i = 1; i <= n; ++i)
fin>>a[i];
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
s = 0;
for(int l = i; l <= j; ++l){
s += a[l];
}
if(s > smax){
smax = s;
poz1 = i;
poz2 = j;
}
}
}
fout<<smax<<" "<<poz1<<" "<<poz2;
}
