Cod sursa(job #25500)
Utilizator | Data | 4 martie 2007 12:45:25 | |
---|---|---|---|
Problema | Buline | Scor | 0 |
Compilator | c | Status | done |
Runda | preONI 2007, Runda 3, Clasa a 9-a si gimnaziu | Marime | 0.5 kb |
#include <stdio.h>
#define MAX 200000
int main()
{
long int n, i, s, smax, p, l;
int x[MAX], y;
FILE *f=fopen("buline.in","rt");
fscanf(f,"%li",&n);
s=0; p=1; smax=-1;
for(i=0; i<n; i++)
{
fscanf(f,"%i %i", &x+i, &y);
if (y==0) s-=x;
if (y==1) s+=x;
if (s>0)
{
if (s>smax) smax=s, l=i+1-p;
} else s=0, p=i+1;
}
fclose(f);
f=fopen("buline.out","wt");
fprintf(f, "%li %li %li\n", smax, p, l);
fclose(f);
return 0;
}