Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(vec) for(auto& i : vec) cin >> i
- #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
- #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
- #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " " << s << "\n";
- #define fixed(n) cout << fixed << setprecision(n);
- #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define fill(vec, value) memset(vec, value, sizeof(vec));
- #define Num_of_Digits(n) ((int)log10(n)+1)
- #define all(vec) vec.begin(),vec.end()
- #define rall(vec) vec.rbegin(),vec.rend()
- #define sz(x) int(x.size())
- #define fi first
- #define se second
- #define Pair pair < int, int >
- #define ll long long
- #define ull unsigned long long
- #define Mod 1'000'000'007
- #define INF 2'000'000'000
- #define PI acos(-1)
- void Code_Crush(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll n, x;
- vector < int > machines(2 * 1e5 + 1);
- bool can_achieve(ll seconds){
- ll products = 0;
- for(auto& it : machines){
- products += seconds / it;
- if(products >= x) return true;
- }
- return products >= x;
- }
- ll Binary_Search(){
- ll l = 1, r = 1e18, best = -1;
- while(l <= r){
- ll m = l + (r - l) / 2;
- (can_achieve(m) ? r = m - 1, best = m : l = m + 1);
- }
- return best;
- }
- int main(){
- Code_Crush();
- cin >> n >> x;
- machines.resize(n);
- cin(machines);
- sort(all(machines));
- cout << Binary_Search();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement