Cod sursa(job #3355320)

Utilizator wizardragonWizard Dragon wizardragon Data 22 mai 2026 15:32:37
Problema Secventa 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>
using namespace std;
typedef float ld;
int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  freopen("secv3.in","r",stdin);
  freopen("secv3.out","w",stdout);
  int n,l,r;
  cin>>n>>l>>r;
  vector<int> c(n),t(n);
  for(auto&x:c)cin>>x;
  ld low=0,high=0;
  for(int i=0;i<n;i++) {
    cin>>t[i];
    high=max(high,(ld)c[i]/(ld)t[i]);
  }
  vector<ld> s(n+1);
  deque<int> inds;
  auto isok=[&](ld val) {
    for(int i=0;i<n;i++){
      s[i+1]=s[i]+c[i]-t[i]*val;
    }
    inds.clear();
    for(int i=1;i<=n;i++){
      if(i>=l){
        while(!inds.empty()&&s[i-l]<=s[inds.back()]){
          inds.pop_back();
        }
        inds.push_back(i-l);
      }
      if(!inds.empty()&&i-(inds.front()+1)+1>r){
        inds.pop_front();
      }
      if(!inds.empty()&&s[i]-s[inds.front()]>=0){
        return 1;
      }
    }
    return 0;
  };
  while(high-low>1e-3){
    ld mid=(low+high)/2;
    if(isok(mid)){
      low=mid;
    }else{
      high=mid;
    }
  }
  cout<<fixed<<setprecision(2)<<low<<"\n";
  return 0;
}