From b605576bc0d17ab9433128f5d05815abff091985 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 30 Dec 2020 21:17:21 +0800 Subject: [PATCH] =?UTF-8?q?P3853=20[TJOI2007]=E8=B7=AF=E6=A0=87=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R44439758 --- problem/P3853/P3853.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 problem/P3853/P3853.cpp diff --git a/problem/P3853/P3853.cpp b/problem/P3853/P3853.cpp new file mode 100644 index 00000000..70b2adca --- /dev/null +++ b/problem/P3853/P3853.cpp @@ -0,0 +1,30 @@ +#include + +using namespace std; + +int l, r, n, k, a[100005]; + +bool check(int mid) { + int m = 0; + for (int i = 2; i <= n; i++) { + if (a[i] - a[i - 1] >= mid) { + m += (a[i] - a[i - 1]) / mid; + if ((a[i] - a[i - 1]) % mid == 0) m--; + } + } + return m <= k; +} + +int main() { + cin >> r >> n >> k; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + while (l < r) { + int mid = l + r >> 1; + if (check(mid)) r = mid; + else l = mid + 1; + } + cout << l << endl; + return 0; +}