Skip to content

Commit bff2fe2

Browse files
authored
Merge pull request #408 from xirc/atcoder/typical90A
AtCoder/Typical90A
2 parents 705bd35 + 9a9b9bf commit bff2fe2

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

atcoder/typical90/A/main.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
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+
17+
using namespace std;
18+
using ll = int64_t;
19+
using ff = long double;
20+
21+
int N, L, K;
22+
vector<int> A;
23+
vector<int> B;
24+
25+
bool pass(int T) {
26+
int c = 0;
27+
int x = 0;
28+
for (auto b : B) {
29+
x += b;
30+
if (x >= T) {
31+
++c;
32+
x = 0;
33+
}
34+
}
35+
return c >= K + 1;
36+
}
37+
38+
int solve() {
39+
B.push_back(A[0]);
40+
for (int i = 1; i < N; ++i) {
41+
B.push_back(A[i] - A[i-1]);
42+
}
43+
B.push_back(L - A[N-1]);
44+
45+
int ok = 1, ng = 1e9+1;
46+
return binary_search(pass, ng, ok);
47+
}
48+
49+
int main() {
50+
ios_base::sync_with_stdio(false);
51+
cin.tie(0); cout.tie(0);
52+
53+
cin >> N >> L >> K;
54+
A.assign(N, 0);
55+
for (auto &ai : A) cin >> ai;
56+
cout << solve() << endl;
57+
58+
return 0;
59+
}

lib/cpalgo/util/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ We can use this technique in many problems. It's a pretty powerful technique.
2727
- [Widespread](https://atcoder.jp/contests/abc063/tasks/arc075_b)
2828
- [射撃王](https://atcoder.jp/contests/abc023/tasks/abc023_d)
2929
- [壁抜け](https://atcoder.jp/contests/abc020/tasks/abc020_c)
30+
- [001 - Yokan Party](https://atcoder.jp/contests/typical90/tasks/typical90_a)
3031

3132

3233
## Dice

0 commit comments

Comments
 (0)