diff --git a/atcoder/typical90/A/main.cpp b/atcoder/typical90/A/main.cpp new file mode 100644 index 00000000..2f23ebd6 --- /dev/null +++ b/atcoder/typical90/A/main.cpp @@ -0,0 +1,59 @@ +#include + +inline int64_t binary_search( + std::function const& predicate, + int64_t ng, + int64_t ok +) { + assert(!predicate(ng) && predicate(ok)); + while (abs(ok - ng) > 1) { + auto m = (ok + ng) / 2; + if (predicate(m)) ok = m; + else ng = m; + } + return ok; +} + +using namespace std; +using ll = int64_t; +using ff = long double; + +int N, L, K; +vector A; +vector B; + +bool pass(int T) { + int c = 0; + int x = 0; + for (auto b : B) { + x += b; + if (x >= T) { + ++c; + x = 0; + } + } + return c >= K + 1; +} + +int solve() { + B.push_back(A[0]); + for (int i = 1; i < N; ++i) { + B.push_back(A[i] - A[i-1]); + } + B.push_back(L - A[N-1]); + + int ok = 1, ng = 1e9+1; + return binary_search(pass, ng, ok); +} + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(0); cout.tie(0); + + cin >> N >> L >> K; + A.assign(N, 0); + for (auto &ai : A) cin >> ai; + cout << solve() << endl; + + return 0; +} \ No newline at end of file diff --git a/lib/cpalgo/util/README.md b/lib/cpalgo/util/README.md index a5b6f7ed..f9fd7f85 100644 --- a/lib/cpalgo/util/README.md +++ b/lib/cpalgo/util/README.md @@ -27,6 +27,7 @@ We can use this technique in many problems. It's a pretty powerful technique. - [Widespread](https://atcoder.jp/contests/abc063/tasks/arc075_b) - [射撃王](https://atcoder.jp/contests/abc023/tasks/abc023_d) - [壁抜け](https://atcoder.jp/contests/abc020/tasks/abc020_c) +- [001 - Yokan Party](https://atcoder.jp/contests/typical90/tasks/typical90_a) ## Dice