-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributing_ballot_boxes.cpp
51 lines (39 loc) · 1.02 KB
/
distributing_ballot_boxes.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define long long long int
#define pii pair<int, int>
#define pll pair<long, long>
#define fst first
#define snd second
#define all(ds) (ds).begin(), (ds).end()
#define rall(ds) (ds).rbegin(), (ds).rend()
#define size(ds) (int) (ds).size()
#define pq priority_queue
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
const int MAX = 5e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, B;
while (cin >> N >> B, ~N || ~B) {
int a[MAX], r = INT_MIN;
for (int i = 0; i < N; i++) {
cin >> a[i];
r = max(r, a[i]);
}
int l = 1, ans;
while (l <= r) {
int mid = (l + r) / 2;
long cnt = 0LL;
for (int i = 0; i < N; i++)
cnt += (a[i] + mid - 1) / mid;
if (cnt > B) l = mid + 1;
else r = mid - 1, ans = mid;
}
cout << ans << "\n";
}
}