Cod sursa(job #996234)

Utilizator danutbodbodnariuc danut danutbod Data 11 septembrie 2013 15:02:16
Problema Secventa 3 Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#define Nmax 30003
using namespace std;
ifstream f("secv3.in");
ofstream g("secv3.out");
int vc[Nmax],vt[Nmax],lung,a,b,L,U,n,i,pi,k;
double maxi;
int main()
{
    f>>n>>L>>U;
    for(i=1;i<=n;i++)f>>vc[i];
    for(i=1;i<=n;i++)f>>vt[i];
    for(i=1;i<=L;i++)a+=vc[i],b+=vt[i];
    lung=L;
    maxi=1.0*a/b;pi=1;
    while(i<=n){
        k=0;//modif
       while(lung<U && 1.0*a/b<=1.0*(a+vc[i])/(b+vt[i])&&i<=n){
         if(maxi<1.0*(a+vc[i])/(b+vt[i]))maxi=1.0*(a+vc[i])/(b+vt[i]);
         a+=vc[i],b+=vt[i];
         lung++,i++,k++;
       }
       while(lung>L && 1.0*a/b<=1.0*(a-vc[pi])/(b-vt[pi])&&i<=n){
           if(maxi<1.0*(a-vc[pi])/(b-vt[pi]))maxi=1.0*(a-vc[pi])/(b-vt[pi]);
           a-=vc[pi],b-=vt[pi];
           lung--,pi++,k++;
       }
       if(k==0){a-=vc[pi];b-=vt[pi];pi++;a+=vc[i];b+=vt[i];i++;}
    }
    g<<maxi<<'\n';
    return 0;
}