From 105979fd16129b9df07afe4f6bea18a0a91a8a0f Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 3 Jan 2021 16:02:53 +0800 Subject: [PATCH] =?UTF-8?q?P2678=20[NOIP2015=20=E6=8F=90=E9=AB=98=E7=BB=84?= =?UTF-8?q?]=20=E8=B7=B3=E7=9F=B3=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R44577346 --- Luogu/problem/P2678/P2678.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Luogu/problem/P2678/P2678.cpp diff --git a/Luogu/problem/P2678/P2678.cpp b/Luogu/problem/P2678/P2678.cpp new file mode 100644 index 00000000..0a542fc3 --- /dev/null +++ b/Luogu/problem/P2678/P2678.cpp @@ -0,0 +1,37 @@ +#include + +using namespace std; + +int n, m, l, r, mid, ans, a[50005]; + +bool check(int x) { + int now = 0, cnt = 0, i = 0; + for (int i = 1; i <= n; i++) { + if (a[i] - a[now] < x) { + cnt++; + } else { + now = i; + } + } + return cnt <= m; +} + +int main() { + cin >> r >> n >> m; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + a[n+1] = r; + l = 1; + while (l <= r) { + mid = l + r >> 1; + if (check(mid)) { + ans = mid; + l = mid + 1; + } else { + r = mid - 1; + } + } + cout << ans << endl; + return 0; +}