-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuitar_Lesson.cpp
More file actions
48 lines (44 loc) · 875 Bytes
/
Copy pathGuitar_Lesson.cpp
File metadata and controls
48 lines (44 loc) · 875 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
45
46
47
48
// Baekjoon 2343
// Binary Search
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long int N, M, input, max_blueray, max_time;
vector<long long int>lesson;
void p_search(long long int left, long long int right) {
long long int mid, br_len, br_count;
while (left <= right) {
mid = (left + right) / 2;
br_len = 0;
br_count = 1;
for (long long int i{ 0 }; i < N; i++) {
if (br_len + lesson[i] > mid) {
br_len = lesson[i];
br_count++;
}
else {
br_len += lesson[i];
}
}
if (br_count > M) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
cout << left << endl;
}
int main() {
cin >> N >> M;
for (long long int i{ 0 }; i < N; i++) {
cin >> input;
lesson.push_back(input);
max_blueray += input;
if (input > max_time) {
max_time = input;
}
}
p_search(max_time, max_blueray);
}