Cod sursa(job #2476759)
Utilizator | Data | 19 octombrie 2019 11:22:49 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream f ("ssm.in");
ofstream g ("ssm.out");
int n, v,s,mn,maxi,r,i,dr,ind,st, last;
int main()
{
f>>n;
f>>v;
s=v;
r=s;
maxi=r;
last=s;
for (i=2;i<=n;i++)
{
f>>v;
s=last+v;
if (last<mn)
{
mn=last;
ind=i-1;
}
r=s-mn;
if (maxi<r) {maxi=r;dr=i;st=ind+1;}
last=s;
}
g<<maxi<<" "<<st<<" "<<dr;
return 0;
}