Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "CIRCLES"
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e4 + 5;
- constexpr ll Inf = 1e17;
- int n, f[N], dp[N], last[N];
- struct Circle
- {
- ll l, r;
- } a[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- {
- ll x, r;
- cin >> x >> r;
- a[i].l = x - r;
- a[i].r = x + r;
- }
- }
- void Solve()
- {
- a[0].l = -Inf;
- a[0].r = Inf;
- sort(a, a + n + 1, [&](const Circle &x, const Circle &y)
- { return x.r < y.r || (x.r == y.r && x.l > y.l); });
- for (int i = 0; i <= n; ++i)
- {
- int l = 0, mid, h = i - 1;
- while (l <= h)
- {
- mid = (l + h) / 2;
- if (a[mid].r <= a[i].l)
- l = mid + 1;
- else
- h = mid - 1;
- }
- last[i] = h;
- }
- for (int i = 0; i <= n; ++i)
- {
- for (int j = 0; j < i; ++j) // assume a[j].r <= a[i].r
- if (a[i].l <= a[j].l)
- {
- dp[j + 1] = dp[j];
- dp[j + 1] = max(dp[j + 1], dp[last[j] + 1] + f[j]);
- }
- else
- dp[j + 1] = dp[j];
- f[i] = dp[i] + 1;
- }
- cout << f[n] - 1;
- }
- int32_t main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement