Advertisement
YEZAELP

TUMSO18-F: ab gift

Jul 20th, 2021
1,508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 1e6 + 10;
  5. const int Const = 1e4;
  6. using db = double;
  7. const db INF = 1e9;
  8. db A[N], B[N];
  9.  
  10. int main(){
  11.  
  12.     int n;
  13.     scanf("%d", &n);
  14.  
  15.     for(int i=1;i<=n;i++){
  16.         int a, b;
  17.         cin >> a >> b;
  18.         A[i] = (db) a;
  19.         B[i] = (db) b / Const;
  20.     }
  21.  
  22.     db mx = -INF;
  23.     int l = 1, r = 0;
  24.     db sum = 0.0, prod = 1.0;
  25.     while(l <= n){
  26.         if(sum < Const and r < n){ /// right
  27.             r ++;
  28.             sum += (db)(A[r] / B[r]);
  29.             prod *= (db) B[r];
  30.             mx = max(mx, sum * prod);
  31.         }
  32.         else { /// left
  33.             sum -= (db)(A[l] / B[l]);
  34.             prod /= (db) B[l];
  35.             mx = max(mx, sum * prod);
  36.             l ++;
  37.         }
  38.     }
  39.  
  40.     printf("%.0f", mx * Const);
  41.  
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement