Pagini recente » Cod sursa (job #1651195) | Istoria paginii runda/rar16/clasament | Cod sursa (job #3278761) | Cod sursa (job #1707194) | Cod sursa (job #447023)
Cod sursa(job #447023)
#include <cstdio>
#include <cstdlib>
#define IN "ssm.in"
#define OUT "ssm.out"
#define MAX_N 7000005
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define oo 2147483647
#define hg 8192
int *V = (int*) malloc(sizeof(int) * MAX_N), N, poz;
char ch[hg];
inline void cit (int &x)
{
int semn = 1;
x = 0;
if (ch[0]=='\0') fread (ch, 1, hg, stdin);
else while ((ch[poz] < '0' || ch[poz] > '9') && ch[poz] != '-')
if (++poz == hg)
fread (ch, 1, hg, stdin), poz = 0;
if (ch[poz] == '-')
{
semn = -1;
if (++poz == hg)
fread (ch, 1, hg, stdin), poz = 0;
}
while (ch[poz] >= '0' && ch[poz] <= '9')
{
x = x * 10 + ch[poz] - '0';
if (++poz == hg)
fread (ch, 1, hg, stdin), poz = 0;
}
x *= semn;
}
int main()
{
freopen(IN,"r",stdin);
freopen(OUT,"w",stdout);
int i;
for ( cit(N), i = 1; i <= N; i++)
cit(V[i]);
int rez = -oo, min = 0, poz = 0, st = 0, dr = 0;
for (i = 1; i <= N; i++)
{
V[i] += V[i - 1];
if (rez < V[i] - min)
rez = V[i] - min, st = poz + 1, dr = i;
if (min > V[i])
min = V[i], poz = i;
}
printf("%d %d %d",rez,st,dr);
return 0;
}