Cod sursa(job #38457)

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