Advertisement
YEZAELP

TOI11: Labor at the Deck

Jun 4th, 2020 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using lli = long long ;
  5. const lli INF = 2e18;
  6. const lli N = 2e12;
  7. const lli M = 1e6 + 10;
  8. lli tim[M];
  9. lli n, m;
  10.  
  11. lli product(lli t){
  12.     lli cnt = 0;
  13.     for(int i=1;i<=m;i++){
  14.         if(tim[i] > t) break;
  15.         cnt += (lli) t/ tim[i];
  16.     }
  17.     return cnt;
  18. }
  19.  
  20. int main(){
  21.  
  22.     scanf("%lld%lld", &m, &n);
  23.  
  24.     for(int i=1;i<=m;i++)
  25.         scanf("%lld", &tim[i]);
  26.  
  27.     sort(tim + 1, tim + m + 1);
  28.  
  29.     lli l = 1, r = N, mn = INF;
  30.     while(l<=r){
  31.         lli mid = (l + r)/ 2;
  32.         if(product(mid) >= n)
  33.             mn = min(mn, mid), r = mid - 1;
  34.         else
  35.             l = mid + 1;
  36.     }
  37.  
  38.     printf("%lld", mn);
  39.  
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement