Created
July 25, 2019 13:25
-
-
Save surinoel/194732c16d7e5fad061459950cc7b94d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int a[100001]; | |
| int main(void) { | |
| ios_base::sync_with_stdio(false); | |
| cin.tie(nullptr); | |
| int n, m; | |
| cin >> n >> m; | |
| for (int i = 0; i < m; i++) { | |
| cin >> a[i]; | |
| } | |
| int ans; | |
| int left = 0, right = n; | |
| int mid = (left + right) / 2; | |
| while (left <= right) { | |
| int d = a[0], idx = 0; | |
| bool ok = true; | |
| for (int i = 0; i <= n; i++) { | |
| if (!(i >= d - mid && i <= d + mid)) { | |
| if (++idx == m) { | |
| ok = false; | |
| goto end; | |
| } | |
| d = a[idx]; | |
| if (!(i - 1 >= d - mid && i - 1 <= d + mid)) { | |
| ok = false; | |
| goto end; | |
| } | |
| } | |
| } | |
| end: | |
| if (ok) { | |
| ans = mid; | |
| right = mid - 1; | |
| } | |
| else { | |
| left = mid + 1; | |
| } | |
| mid = (left + right) / 2; | |
| } | |
| cout << ans << '\n'; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment