Pagini recente » Cod sursa (job #424570) | Cod sursa (job #1618993) | Cod sursa (job #773225) | Cod sursa (job #1265110) | Cod sursa (job #495740)
Cod sursa(job #495740)
#include<stdio.h>
struct vector{
int a, b, c;
};
vector best, nr;
int main(){
freopen ("ssm.in", "r", stdin);
freopen ("ssm.out", "w", stdout);
int n, i, k;
scanf("%d ", &n);
best.a=-99999;
nr.b=1;
for(i=1; i<=n; i++){
scanf("%d ", &k);
if(nr.a+k>=k)
nr.a+=k;
else{
nr.a=k;
nr.b=i;
}
nr.c=i;
if(nr.a>best.a)
best=nr;
}
printf("%d %d %d ", best.a, best.b, best.c);
return 0;
}
/*if(best[i-1].a+k>=k){
best[i].a=best[i-1].a+k;
best[i].b=best[i-1].b;
}
else{
best[i].a=k;
best[i].b=i;
}
best[i].c=i;
}
int max=-99999, maxi, maxj;
for(i=1; i<=n; i++)
if(best[i].a>max){
max=best[i].a;
maxi=best[i].b;
maxj=best[i].c;
}
printf("%d %d %d\n", max, maxi, maxj);
return 0;
}
*/