Skip to content

Commit 26e890f

Browse files
committed
atcoder/abc063D
1 parent 43f6c31 commit 26e890f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

atcoder/abc063/D/main.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
#include <bits/stdc++.h>
22

3+
inline int64_t binary_search(
4+
std::function<bool(int64_t)> const& predicate,
5+
int64_t ng,
6+
int64_t ok
7+
) {
8+
assert(!predicate(ng) && predicate(ok));
9+
while (abs(ok - ng) > 1) {
10+
auto m = (ok + ng) / 2;
11+
if (predicate(m)) ok = m;
12+
else ng = m;
13+
}
14+
return ok;
15+
}
16+
317
using namespace std;
4-
using ll = long long;
18+
using ll = int64_t;
519

620
int N, A, B;
721
vector<int> H;
822

9-
bool is_ok(const ll M) {
23+
bool satisfy(const ll M) {
1024
int mxh = *max_element(H.begin(), H.end());
1125
if (mxh / B < M) return true; // prevent an overflow
1226
assert(B * M <= mxh);
@@ -25,17 +39,8 @@ bool is_ok(const ll M) {
2539
}
2640

2741
ll solve() {
28-
ll low = 0, high = 1e15;
29-
assert(!is_ok(low) && is_ok(high));
30-
while (high - low > 1) {
31-
auto m = low + (high - low) / 2;
32-
if (is_ok(m)) {
33-
high = m;
34-
} else {
35-
low = m;
36-
}
37-
}
38-
return high;
42+
ll ng = 0, ok = 1e15;
43+
return binary_search(satisfy, ng, ok);
3944
}
4045

4146
int main() {

0 commit comments

Comments
 (0)