Pagini recente » Cod sursa (job #2471488) | Cod sursa (job #1709729) | Cod sursa (job #3036827) | Cod sursa (job #1446381) | Cod sursa (job #27147)
Cod sursa(job #27147)
#include <stdio.h>
#define in "buline.in"
#define out "buline.out"
#define NMAX 400001
int a[NMAX];
int n, smax;
int best[NMAX];
int main()
{
freopen( in, "r", stdin );
freopen( out, "w", stdout );
scanf( "%d", &n );
int i, col;
for ( i = 1; i <= n; ++i )
{
scanf( "%d%d", &a[i], &col );
if ( col == 0 ) a[i] *= -1;
}
//for ( i = 1; i <= n; printf( "%d ", a[i++] ) );
for ( i = 1; i <= n - 1; ++i )
{
a[i+n] = a[i];
}
//for ( i = 1; i <= 2*n-1; printf( "%d ", a[i++] ) );
best[0] = 0;
smax = 0;
int st = 1, dr = 1;
for ( i = 1; i <= 2*n-1; ++i )
{
best[i] = a[i];
if ( best[i] < best[i-1] + a[i] )
best[i] = best[i-1] + a[i];
if ( best[i] > smax )
smax = best[i];
}
printf( "%d %d %d\n", smax, st, dr );
return 0;
}