Cod sursa(job #2128559)
| Utilizator | Data | 11 februarie 2018 20:13:41 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <iostream>
#include <fstream>
using namespace std;
int a[100],best[100],n,bestsum,pozi,pozs,copie;
int main()
{
int i;
ifstream f ("best.in");
f>>n;
for(i=1; i<=n; i++)
f>>a[i];
bestsum=a[1];
for(i=1; i<=n; i++)
{
best[i]=a[i];
if(best[i]<best[i-1]+a[i])
best[i]=best[i-1]+a[i];
if(bestsum<best[i])
{
bestsum=best[i];
pozs=i;
}
}
copie=bestsum;
pozi=pozs;
while(copie)
{
copie=copie-a[pozi];
pozi--;
}
pozi+=1;
cout<<bestsum<<" "<<pozi<<" "<<pozs;
return 0;
}
