Cod sursa(job #51355)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 11 aprilie 2007 15:16:38
Problema Buline Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<fstream.h>
int main(){
ifstream fin("buline.in");
ofstream fout("buline.out");
long N,p,l;
long a[200000];
long S=0,max=-200000;
long x,y;
fin>>N;
for (long i=0;i<N;i++){
       fin>>x>>y;
       if (y==0) {
	  a[N+i]=(-1)*x;
	  a[i]=(-1)*x;}
       else           {
	  a[N+i]=x;
	  a[i]=x;}     }
for (long j=0;j<N;j++){
     S=0;
     if (a[j]>a[j-1]){
     for (long y=j;y<2*N;y++){
	 S+=a[y];
	 if (S>max){
	     max=S;
	     p=j+1;
	     l=y-j;}}
	 }}
fout<<max<<" "<<p<<" "<<l;
fin.close();
fout.close();
return 0;
}