문제
https://www.acmicpc.net/problem/2792
해설
경우의 수가 너무 많기 때문에 이분탐색을 통해 logn만큼만 탐색하도록 함
코드
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
|
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll n,m,color_cnt,ret = 1e18;
vector<int> v;
bool go(int mid){
ll tmp = 0;
for(int i : v){
tmp += i/mid;
if(i%mid != 0)
tmp++;
}
return n<tmp;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
ll low=1,high=0,mid;
cin >> n >> m;
for(int i=0;i<m;i++){
cin >> color_cnt;
v.push_back(color_cnt);
high = max(high,color_cnt);
}
while(low<=high){
mid = (low+high)/2;
if(go(mid)){
low = mid+1;
}
else{
high = mid-1;
ret = mid;
}
}
cout << ret;
return 0;
}
|
cs |
'백준 알고리즘(C++)' 카테고리의 다른 글
백준 6236 용돈 관리 ( C++ ) (0) | 2024.09.10 |
---|---|
백준 2343번 기타 레슨 ( C++ ) (0) | 2024.09.10 |
백준 3190번 뱀 ( C++ ) (2) | 2024.09.08 |
백준 12100번 2048 (Easy) ( C++ ) (0) | 2024.09.06 |
백준 14889번 스타트와 링크 ( C++ ) (0) | 2024.09.05 |