Advertisement
welleyth

ROI 2019-2020. Task B

Sep 6th, 2021
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. const int INF=(int)1e18;
  8. const double eps=1e-5;
  9.  
  10. signed main() {
  11.     ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
  12.  
  13.     ///freopen("input.txt","r",stdin);
  14.     ///freopen("output.txt","w",stdout);
  15.  
  16.     int n;
  17.     cin >> n;
  18.  
  19.     int dist=0,mn=(int)1e18,mx=-1;
  20.  
  21.     int speed[n];
  22.     for(int i = 0 ; i < n ; i++)
  23.     {
  24.         cin >> speed[i];
  25.         mn=min(mn,speed[i]);
  26.         mx=max(mx,speed[i]);
  27.     }
  28.  
  29.     int d[n];
  30.     double tt=0;
  31.     for(int i = 0 ; i < n ; i++)
  32.     {
  33.         cin >> d[i];
  34.         dist+=d[i];
  35.         tt+=1.0*d[i]/speed[i];
  36.     }
  37.  
  38.  
  39.  
  40.     int m;
  41.     cin >> m;
  42.  
  43.     double limit[m];
  44.     limit[0]=0;
  45.  
  46.     if(m!=1)
  47.     {
  48.         for(int i = 1 ; i < m ; i++)
  49.         {
  50.             cin >> limit[i];
  51.         }
  52.     }
  53.  
  54.     int payments[m];
  55.     for(int i=0;i<m;i++)
  56.     {
  57.         cin >> payments[i];
  58.     }
  59.  
  60.     double time[m];
  61.     for(int i=0;i<m;i++)
  62.     {
  63.         time[i]=0;
  64.         for(int j=0;j<n;j++)
  65.         {
  66.             time[i]+=1.0*d[j]/(speed[j]+limit[i]);
  67.         }
  68.     }
  69.     int q;
  70.     cin >> q;
  71.     while(q--)
  72.     {
  73.         int s,f;
  74.         cin >> s >> f;
  75.         int L=0,R=m;
  76.         int t=f-s;
  77.         if(t>=tt)
  78.         {
  79.             cout << "0\n";
  80.             continue;
  81.         }
  82.         while(R-L>1)
  83.         {
  84.             int m=(R+L)/2;
  85.             if(time[m]>t)
  86.                 L=m;
  87.             else
  88.                 R=m;
  89.         }
  90.         if(time[R]>t)
  91.             cout << payments[R] << "\n";
  92.         else
  93.             cout << payments[L] << "\n";
  94.     }
  95.  
  96.  
  97.  
  98.     return 0;
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement