Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <cstdio>
  6. using namespace std;
  7. long long n, m, q;
  8. vector<long long> u, l, a, f;
  9. long double fun(long double x) {
  10.     long double ans = 0.0;
  11.     for (long long i = 0; i < n; i++) {
  12.         ans += l[i] / (u[i] + x);
  13.     }
  14.     return ans;
  15. }
  16. int main(){
  17.     //freopen("Hello.txt", "w", stdout);
  18.     cout.precision(20);
  19.     long long x;
  20.     cin >> n;
  21.     for (long long i = 0; i < n; i++) {
  22.         cin >> x;
  23.         u.push_back(x);
  24.     }
  25.     for (long long i = 0; i < n; i++) {
  26.         cin >> x;
  27.         l.push_back(x);
  28.     }
  29.     cin >> m;
  30.     for (long long i = 0; i < m-1; i++) {
  31.         cin >> x;
  32.         a.push_back(x);
  33.     }
  34.     for (long long i = 0; i < m; i++) {
  35.         cin >> x;
  36.         f.push_back(x);
  37.     }
  38.     long double s, s2, t, time;
  39.     long long gl, gr;
  40.     time = fun(0);
  41.     cin >> q;
  42.     if (n == 1) {
  43.         while (q--) {
  44.             int x, y;
  45.             cin >> x>> y;
  46.             long double v1, e;
  47.             if (y - x > time) {
  48.                 cout<< 0 << endl;
  49.                 goto W;
  50.             }
  51.  
  52.             v1 = l[0] / (y - x);
  53.             e = v1 - u[0];
  54.             if (m == 1 && time > y - x) {
  55.                 cout << f.back() << endl;
  56.                 goto W;
  57.             }
  58.             /*if (time-y+x==0) {
  59.             cout « 0 « endl;
  60.             goto W;
  61.             }*/
  62.             for (int i = 0; i < m - 1; ++i)
  63.                 if (e <= a[i]) {
  64.                     cout << f[i] << endl;
  65.                     goto W;
  66.                 }
  67.             cout << f[m - 1] << endl;
  68.         W:;
  69.         }
  70.  
  71.     }
  72.     if (m == 1 && n != 1) {
  73.         for (long long i = 0; i < q; i++) {
  74.             cin >> s >> s2;
  75.             t = s2 - s;
  76.             if (t <= time) {
  77.                 cout << f[0] << '\n';
  78.             }
  79.             else {
  80.                 cout << '0' << '\n';
  81.             }
  82.         }
  83.     }
  84.     else {
  85.         for (long long i = 0; i < q; i++) {
  86.             cin >> s >> s2;
  87.             t = s2 - s;
  88.             gl = -1;
  89.             gr = m;
  90.             while (gr - gl != 1) {
  91.                 long long mm = (gr + gl) / 2;
  92.                 if (fun(a[mm]) > t) {
  93.                     gl = mm;
  94.                 }
  95.                 else {
  96.                     gr = mm;
  97.                 }
  98.             }
  99.             if (t <= time) {
  100.                 cout << f[gr] << '\n';
  101.             }
  102.             else {
  103.                 cout << '0' << '\n';
  104.             }
  105.  
  106.     }
  107.    
  108.     }
  109.     //fclose(stdout);
  110.    
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement