-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee2832.cpp
More file actions
52 lines (39 loc) · 763 Bytes
/
Copy pathbee2832.cpp
File metadata and controls
52 lines (39 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Contest : Beecrowd
* Problem : 2832 - Cápsulas
* Link : https://judge.beecrowd.com/pt/problems/view/2832
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
ll n, f;
vector<ll> cycles;
bool isValid(ll x) {
ll cnt = 0;
for (auto c : cycles) cnt += x / c;
cerr << "mid = " << x << " cnt = " << cnt << "\n";
return cnt >= f;
}
ll bs() {
ll l = 1, r = 1e18, m, ans = -1;
while (l <= r) {
m = l + (r - l) / 2;
if (isValid(m)) {
ans = m;
r = m - 1;
}
else {
l = m + 1;
}
}
return ans;
}
int main() {
fastio
cin >> n >> f;
cycles.resize(n);
for (auto &i : cycles) cin >> i;
cout << bs() << "\n";
return 0;
}