[백준] 2792 보석 상자
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int N, M;
vector<int> bosuk;
bool decision(int x) {
int cnt = 0;
for (int i = 0; i < M; ++i) {
cnt += (bosuk[i] / x);
if (bosuk[i] % x) cnt++;
}
return cnt <= N;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> N >> M;
int maxInput = 0;
for (int i = 0; i < M; ++i) {
int input;
cin >> input;
bosuk.push_back(input);
maxInput = max(input, maxInput);
}
int l = 1;
int r = maxInput;
while (l + 1< r) {
int mid = (l + r) / 2;
if (decision(mid)) r = mid;
else l = mid;
}
cout << r;
return 0;
}