Advertisement
mickypinata

TUMSO18: AB Gift

Jul 23rd, 2021
1,129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e6;
  5.  
  6. int arrA[N + 1];
  7. double arrB[N + 1];
  8.  
  9. int main(){
  10.  
  11.     int nItems;
  12.     scanf("%d", &nItems);
  13.     arrB[0] = 1;
  14.     for(int i = 1; i <= nItems; ++i){
  15.         int bVal;
  16.         scanf("%d%lf", &arrA[i], &arrB[i]);
  17.         arrB[i] /= 1e4;
  18.     }
  19.     int j = 0;
  20.     double mx = 0;
  21.     double sum = 0;
  22.     double product = 1;
  23.     for(int i = 1; i <= nItems; ++i){
  24.         while(j < nItems && sum < 1e4){
  25.             sum += arrA[j + 1] / arrB[j + 1];
  26.             product *= arrB[j + 1];
  27.             ++j;
  28.         }
  29.         mx = max(mx, sum * product);
  30.         sum -= arrA[i - 1] / arrB[i - 1];
  31.         product /= arrB[i - 1];
  32.     }
  33.     printf("%.0f", mx * 1e4);
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement