Cod sursa(job #627530)
Utilizator | Data | 30 octombrie 2011 08:50:08 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n,p,u,mx;
int main(){
int x,i,s,bst=0,p1=1;
f>>n;
f>>x;
p=1;u=1;mx=x;
for(i=2;i<=n;i++){
f>>x;
s=bst+x;
if(x>s){bst=x;p1=i;} else bst=s;
if(bst>mx){p=p1;u=i;mx=bst;} }
g<<mx<<' '<<p<<' '<<u<<'\n';
}