-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16401.cpp
More file actions
44 lines (34 loc) · 764 Bytes
/
Copy path16401.cpp
File metadata and controls
44 lines (34 loc) · 764 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
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long lld;
vector<lld> v;
lld M, N, a, maxLength=0;
void binarySearch(lld low, lld high){
if(low > high) return;
lld mid = (low+high)/2, sumFregment = 0;
for(int i=0; i<N; i++){
sumFregment += v[i]/mid;
if(sumFregment >= M) break;
}
if(sumFregment >= M){
maxLength = mid;
binarySearch(mid+1, high);
}else{
binarySearch(low, mid-1);
}
}
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio();
cin >> M >> N;
for(int i=0; i<N; i++){
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
binarySearch(1, 1e+9);
cout << maxLength;
}