forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathballotboxes.cpp
45 lines (36 loc) · 1.04 KB
/
ballotboxes.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
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
class mycomparison {
public:
bool operator() (const pair<ll,ll>& lhs, const pair<ll,ll>& rhs) const {
if(ceil(lhs.first / double(lhs.second)) == ceil(rhs.first / double(rhs.second))) {
return lhs.second > rhs.second;
}
return ceil(lhs.first / double(lhs.second)) < ceil(rhs.first / double(rhs.second));
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, b;
while(cin >> n && cin >> b && !(n == -1 || b == -1)) {
priority_queue<pair<ll, ll>, vector<pair<ll,ll>>, mycomparison> q;
for(ll i = 0; i < n; i++) {
ll temp;
cin >> temp;
q.push({temp, 1});
}
b -= n;
for(ll i = 0; i < b; i++) {
pair<int, int> p = q.top();
q.pop();
p.second++;
q.push(p);
}
cout << ceil(q.top().first / double(q.top().second)) << endl;
}
}