Advertisement
AdamTheGreat

Coolerthanyou.com

Nov 3rd, 2022 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main(void) {
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie(NULL);
  9.     long long n, t;
  10.     cin >> n >> t;
  11.     vector<long long> machines;
  12.     long long biggest = 0;
  13.     for (long long i = 0; i < n; ++i) {
  14.         long long temp;
  15.         cin >> temp;
  16.         machines.push_back(temp);
  17.         if (temp > biggest) biggest = temp;
  18.     }
  19.     long long lbound = 0, ubound = t*biggest, mid;
  20.     long long ans = 0;
  21.     while (lbound <= ubound) {
  22.         mid = (lbound+ubound)/2;
  23.         int time = 0;
  24.         for (long long i = 0; i < n; ++i) {
  25.             time += mid/machines[i];
  26.         }
  27.         if (time == t) {
  28.             ans = mid;
  29.             break;
  30.         } else if (time < t) {
  31.             lbound = mid+1;
  32.         } else {
  33.             ans = mid;
  34.             ubound = mid-1;
  35.         }
  36.     }
  37.     cout << ans << endl;
  38. }
Tags: C++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement