1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, len; std::cin >> n >> len;
std::vector<std::array<i64, 2>> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i][0] >> a[i][1]; }
i64 l = 0, r = 2E9; while (l < r) { i64 mid = l + r >> 1; auto check = [&](i64 x) { std::vector<std::array<i64, 2>> seg; for (int i = 0; i < n; i++) { if (x >= a[i][1]) { i64 t = x - a[i][1]; seg.push_back({a[i][0] - t, a[i][0] + t}); } } std::sort(seg.begin(), seg.end()); if (seg.empty() || seg[0][0] > 1) { return false; } i64 right = seg[0][1]; for (int i = 1; i < seg.size(); i++) { if (right + 1 < seg[i][0]) { return false; } right = std::max(right, seg[i][1]); } return right >= len; }; if (!check(mid)) { l = mid + 1; } else { r = mid; } } std::cout << l << "\n"; return 0; }
|