text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int MAX = -1e6 - 500; long long n, x[100005], h[100005], h_new[100005]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } for (int i = 0; i < n - 1; i++) { h_new[i] = x[i + 1] - x[i] - 1; } int ans = 2; if (n < 2) { cout << n; return 0; } h[0] = 0; for (int i = 1; i < n - 1; i++) { if (h_new[i - 1] >= h[i]) { ans++; h[i] = 0; } else if (h_new[i] >= h[i]) { h_new[i] -= h[i]; h[i] = 0; ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int lala = 2e9 + 1; int max(int a, int b) { return a > b ? a : b; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; pair<int, int> arr[100005]; int dp[3][100005]; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; arr[n].first = lala, arr[n].second = 0; dp[0][0] = 0; dp[1][0] = 1; dp[2][0] = arr[0].first + arr[0].second < arr[1].first ? 1 : 0; for (int i = 1; i < n; i++) { dp[0][i] = max(dp[0][i - 1], max(dp[1][i - 1], dp[2][i - 1])); if (arr[i].first - arr[i].second > arr[i - 1].first) { if (arr[i].first - arr[i].second > arr[i - 1].first + arr[i - 1].second) { dp[1][i] = dp[0][i] + 1; } else { dp[1][i] = dp[1][i - 1] + 1; } } else { dp[1][i] = dp[0][i]; } if (arr[i].first + arr[i].second < arr[i + 1].first) { dp[2][i] = dp[0][i] + 1; } else { dp[2][i] = dp[0][i]; } } cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl; }
#include <bits/stdc++.h> using namespace std; int abso(int a) { return a > 0 ? a : (-a); } int cdiv(int a, int b) { return a / b + ((a % b) > 0); } int mul(int a, int b) { int res = 0; while (b) { if (b & 1) res = (res + a) % (int)(1e9 + 7); a = (a + a) % (int)(1e9 + 7); b = b / 2; } return res; } int bexp(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b = b / 2; } return res; } int inv(int a) { return bexp(a, (int)(1e9 + 7) - 2); } int n; const int N = 100050; int dp[N][2][2]; int x[N], h[N]; int solve(int idx, int left, int right) { if (idx >= n + 1) return 0; int& ans = dp[idx][left][right]; if (ans != -1) return ans; ans = solve(idx + 1, 0, 0); if ((left == 0 && right == 0) || left == 1) { if (((x[idx] - h[idx]) > x[idx - 1]) || idx == 1) ans = max(ans, solve(idx + 1, 1, 0) + 1); if (((x[idx] + h[idx]) < x[idx + 1]) || idx == n) ans = max(ans, solve(idx + 1, 0, 1) + 1); } else if (right == 1) { if (((x[idx] + h[idx]) < x[idx + 1]) || idx == n) ans = max(ans, solve(idx + 1, 0, 1) + 1); if (((x[idx] - h[idx]) > (x[idx - 1] + h[idx - 1]))) ans = max(ans, solve(idx + 1, 1, 0) + 1); } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(dp, -1, sizeof(dp)); cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> h[i]; cout << solve(1, 0, 0); }
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int modpro = 988244353; const int di[8] = {-1, 0, 1, 0, -1, 1, 1, -1}, dj[8] = {0, 1, 0, -1, 1, 1, -1, -1}; void solve() { int n; cin >> n; vector<long long int> x(n), h(n); for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } if (n == 1) { cout << 1; return; } int count = 2; long long int left = x[0]; for (int i = 1; i < n - 1; i++) { if (x[i] - h[i] > left) count++, left = x[i]; else if (x[i] + h[i] < x[i + 1]) count++, left = x[i] + h[i]; else left = x[i]; } cout << count; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); cerr << "\n" << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << " ms\n"; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n, ans; cin >> n; int p[n], h[n], l, r; for (int i = 0; i < (n); ++i) { cin >> p[i] >> h[i]; } if (n == 1) { ans = 1; } else { ans = 2; for (int i = (1); i <= (n - 2); ++i) { l = p[i] - p[i - 1]; r = p[i + 1] - p[i]; if (l > h[i]) { ++ans; } else if (r > h[i]) { p[i] += h[i]; ++ans; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000050; const long long Mod = 10007; const int inf = 0x3f3f3f3f; int n, a[100050], r[100050], l[100050]; int main(int argc, const char* argv[]) { scanf("%d", &n); for (int i = 1; i < ((n) + 1); i++) scanf("%d%d", &a[i], &l[i]); a[n + 1] = 0x7f3f3f3f; int cnt = 1; r[1] = a[1]; for (int i = 2; i < ((n) + 1); i++) { if (a[i] - l[i] > r[i - 1]) { r[i] = a[i]; cnt++; } else if (a[i] + l[i] < a[i + 1]) { r[i] = a[i] + l[i]; cnt++; } else r[i] = a[i]; } printf("%d\n", cnt); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n, dp[N + 1][3]; long long int arr[N + 2][2], ans; void solve() { cin >> n; ans = 0; for (long long int i = 0; i < n; i++) { cin >> arr[i + 1][0] >> arr[i + 1][1]; for (long long int j = 0; j < 3; j++) dp[i][j] = 0; } for (long long int j = 0; j < 3; j++) dp[n][j] = 0; arr[0][0] = arr[0][1] = -2e10; arr[n + 1][0] = 2e10; for (int i = 1; i <= n; i++) { if (arr[i - 1][0] < arr[i][0] - arr[i][1]) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1; if (arr[i - 1][0] + arr[i - 1][1] < arr[i][0] - arr[i][1]) { dp[i][0] = max(dp[i][0], dp[i - 1][2] + 1); } } dp[i][1] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])); if (arr[i][0] + arr[i][1] < arr[i + 1][0]) { dp[i][2] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])) + 1; } ans = max(dp[i][0], max(dp[i][1], dp[i][2])); } cout << ans << '\n'; } int main() { cin.tie(0); ios::sync_with_stdio(0); int T = 1; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n; cin >> n; long long x, h; long c = 0; cin >> x >> h; if (n == 1) { cout << 1; return 0; } ++c; h = 0; long long X, H; for (long i = 1; i < n - 1; ++i) { cin >> X >> H; if (h > 0 && h < X - x) { ++c; x += h; h = 0; } if (H < X - x) { ++c; H = 0; } x = X; h = H; } cin >> X >> H; if (h > 0 && h < X - x) { ++c; x += h; h = 0; } ++c; cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int n; cin >> n; vector<pair<long int, long int> > vec; for (long int i = 1; i <= n; i++) { long int a, b; cin >> a >> b; vec.push_back({a, b}); } long int count = 1; long int limit = vec[0].first; for (long int i = 1; i <= n - 2; i++) { if (vec[i].first - vec[i].second > limit) { count++; limit = vec[i].first; } else if (vec[i].first + vec[i].second < vec[i + 1].first) { count++; limit = vec[i].first + vec[i].second; } else { limit = vec[i].first; } } if (n >= 2) count++; cout << count << endl; }
#include <bits/stdc++.h> using namespace std; struct node { int x; int y; } a[100050]; int main() { int n; int ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; a[0].x = -2100000000; a[n + 1].x = 2100000000; for (int i = 1; i <= n; i++) { if (a[i].x - a[i].y > a[i - 1].x) { ans++; continue; } if (a[i].x + a[i].y < a[i + 1].x) { a[i].x += a[i].y; ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; string s, a; cin >> n; long long r = LONG_MIN; long long int x[n + 10], h[n + 10]; for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; x[n] = LONG_MAX; int cnt = 0; for (int i = 0; i < n; i++) { if (x[i] - h[i] > r) { r = x[i]; cnt++; } else if (x[i] + h[i] < x[i + 1]) { r = x[i] + h[i]; cnt++; } else { r = x[i]; } } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x, h; cin >> n; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { cin >> x >> h; v.push_back({x, h}); } if (n < 3) { cout << n; return 0; } int ans = 2; int prevx = v[0].first; for (int i = 1; i < n - 1; i++) { x = v[i].first; h = v[i].second; if (x - h > prevx) { ans++; prevx = x; } else if (x + h < v[i + 1].first) { ans++; prevx = x + h; } else { prevx = x; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; int v[100000 + 1], h[100000 + 1]; int main() { int n, i, sol; cin >> n; for (i = 0; i < n; i++) cin >> v[i] >> h[i]; v[n] = INT_MAX; sol = 1; for (i = 1; i < n; i++) { if (v[i] - v[i - 1] > h[i]) sol++; else if (v[i + 1] - v[i] > h[i]) { v[i] += h[i]; sol++; } } cout << sol; return 0; }
#include <bits/stdc++.h> using namespace std; pair<int, int> p[100005]; int a[100005]; int b[100005]; int main() { int n; cin >> n; int i; int count = 0; int xm, xp; for (i = 0; i < n; i++) { scanf("%d %d", &p[i].first, &p[i].second); a[i] = p[i].first - p[i].second; b[i] = p[i].first + p[i].second; } for (i = 1; i < n - 1; i++) { if (p[i - 1].first < a[i]) { count++; } else if (p[i + 1].first > b[i]) { count++; p[i].first = b[i]; } } if (n > 2) count += 2; else count += n; cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; long long x[100005], h[100005], f[100005][5]; int n; int main() { ios::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n; x[0] = -1e18; x[n + 1] = 1e18; for (int i = 1; i <= n; i++) cin >> x[i] >> h[i]; for (int i = 1; i <= n; i++) { f[i][0] = max(f[i - 1][2], max(f[i - 1][0], f[i - 1][1])); if (x[i] + h[i] < x[i + 1]) f[i][1] = f[i][0] + 1; if (x[i] - h[i] > x[i - 1]) { if (x[i - 1] + h[i - 1] < x[i] - h[i]) f[i][2] = f[i - 1][1] + 1; else f[i][2] = max(f[i - 1][2], f[i - 1][0]) + 1; } } cout << max(f[n][0], max(f[n][1], f[n][2])); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n; if (n == 1) { cout << 1 << '\n'; return 0; } long long int x[n], h[n]; for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } long long int right[n], cnt = 0; right[0] = x[0]; cnt++; for (int i = 1; i < n - 1; i++) { if (x[i] - h[i] > right[i - 1]) { cnt++; right[i] = x[i]; } else if (x[i] + h[i] < x[i + 1]) { cnt++; right[i] = x[i] + h[i]; } else right[i] = x[i]; } ++cnt; cout << cnt << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, cnt, x[100000], h[100000], state[100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> h[i]; for (int i = 0; i < n; ++i) { if (i == 0 || x[i] - x[i - 1] > h[i] + h[i - 1] || (state[i - 1] != 1 && x[i] - x[i - 1] > h[i])) { state[i] = -1; ++cnt; } else if (i == n - 1 || x[i + 1] - x[i] > h[i]) { state[i] = 1; ++cnt; } } cout << cnt; }
#include <bits/stdc++.h> int main() { int tree[100005], h[100005], n, i, cnt; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &tree[i], &h[i]); } if (n >= 3) { cnt = 2; for (i = 1; i < n - 1; i++) { if (tree[i] > tree[i - 1] + h[i]) { cnt++; } else if (tree[i + 1] > tree[i] + h[i]) { cnt++; tree[i] = tree[i] + h[i]; } } printf("%d", cnt); } else { printf("%d", n); } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932; const long long INF = 1e18; long long gcd(long long x, long long y) { return (y == 0 ? x : gcd(y, x % y)); } int main() { vector<long long> x; vector<long long> h; int n, i, r, nb = 1; cin >> n; for (long long i = 0; i < (long long)n; i++) { cin >> r; x.push_back(r); cin >> r; h.push_back(r); } x.push_back(INF); for (long long i = 1; i < (long long)n; i++) { if (x[i] - x[i - 1] > h[i]) nb++; else if (x[i + 1] - x[i] > h[i]) { nb++; x[i] += h[i]; } } cout << nb; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, x1, x2, s = 0; cin >> n; pair<long long, long long> b[n]; for (long long i = 0; i < n; i++) { cin >> b[i].first >> b[i].second; } if (n == 1) { return cout << 1, 0; } else if (n == 2) { return cout << 2, 0; } sort(b, b + n); x1 = b[0].first; for (long long i = 1; i < n - 1; i++) { x2 = b[i + 1].first; if (b[i].first - b[i].second > x1) { x1 = b[i].first; s++; } else if (b[i].first + b[i].second < x2) { x1 = b[i].first + b[i].second; s++; } else { x1 = b[i].first; } } cout << s + 2; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x[100000], h[100000], i; cin >> n; for (i = 0; i < n; i++) cin >> x[i] >> h[i]; int start = x[0]; int count = 1; for (i = 1; i < n - 1; i++) { if (x[i] - x[i - 1] > h[i]) count++; else if (x[i + 1] - x[i] > h[i]) { count++; x[i] += h[i]; } } if (n == 1) count--; cout << count + 1; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int x[100001], h[100001]; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } x[n] = 1e+9 * 2 + 1; int a = 0, b = -1e+9 * 2 + 1; for (int i = 0; i < n; i++) { if (b < x[i] - h[i]) { a++; b = x[i]; } else if (x[i] + h[i] < x[i + 1]) { a++; b = x[i] + h[i]; } else { b = x[i]; } } cout << a << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int inf = 1000009; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int n, x[100009], h[100009], done[100009]; int dp(int c, int last, int sum) { if (c == n) return sum; if (done[c] != -1) return done[c]; if (last >= x[c]) return 0; if (x[c] - h[c] > last) return done[c] = dp(c + 1, x[c], sum + 1); int a = dp(c + 1, x[c] + h[c], sum + 1); int b = dp(c + 1, x[c], sum); return done[c] = max(a, b); } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); memset(done, -1, sizeof done); cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; cout << dp(0, -1000000009, 0); return 0; }
#include <bits/stdc++.h> using namespace std; struct data { int x, h, left, right; }; data tree[100005]; int main() { int n, ans = 2; scanf("%d", &n); if (n == 1) { printf("1\n"); return 0; } for (int i = 0; i < n; i++) { scanf("%d %d", &tree[i].x, &tree[i].h); } for (int j = 1; j < n - 1; j++) { tree[j].left = tree[j].x - tree[j - 1].x; tree[j].right = tree[j + 1].x - tree[j].x; } for (int k = 1; k < n - 1; k++) { if (tree[k].left > tree[k].h) ans++; else if (tree[k].right > tree[k].h) { ans++; tree[k + 1].left -= tree[k].h; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100005][2]; pair<int, int> a[100005]; int main() { int n, x, y; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; a[i] = make_pair(x, y); } int c = 2; int LEFT = 0; int RIGHT = 1; int prev = LEFT; for (int i = 1; i < n - 1; i++) { if (prev == LEFT) { if (a[i - 1].first < a[i].first - a[i].second) { prev = LEFT; c++; } else if (a[i].first + a[i].second < a[i + 1].first) { prev = RIGHT; c++; } else { prev = LEFT; } } else if (prev == RIGHT) { if (a[i - 1].first + a[i - 1].second < a[i].first - a[i].second) { prev = LEFT; c++; } else if (a[i].first + a[i].second < a[i + 1].first) { prev = RIGHT; c++; } else { prev = LEFT; } } } cout << (n == 1 ? 1 : c) << endl; }
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; const int inf = INT_MAX; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } void solve() { int n; cin >> n; vector<pair<int, int>> arr(n); for (int i = 0; i < (n); i++) { cin >> arr[i].first >> arr[i].second; } if (n == 1) { cout << 1 << endl; return; } vector<vector<int>> dp(n, vector<int>(2, 0)); dp[0] = vector<int>{1, 1}; int mid = arr[0].first; int right = arr[0].first; for (int i = (1); i <= (n - 2); i++) { dp[i][0] = dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]); int xi = arr[i].first, hi = arr[i].second; if (xi - hi > mid) dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1); if (xi - hi > right) dp[i][0] = max(dp[i][0], dp[i][1] + 1); if (xi + hi < arr[i + 1].first) dp[i][1]++; mid = arr[i].first; right = arr[i].first + arr[i].second; } int ans = max(dp[n - 2][0], dp[n - 2][1]); cout << ans + 1 << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int x[n]; long long int h[n]; for (int i = 0; i < n; ++i) cin >> x[i] >> h[i]; long long int coun = 0; coun++; for (int i = 1; i < n; ++i) { if (x[i] - h[i] > x[i - 1]) { coun++; } else if (x[i] + h[i] < x[i + 1]) { coun++; x[i] = x[i] + h[i]; } } cout << coun; return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); int n, x[100011], h[100011]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> h[i]; if (n == 1) { puts("1"); return 0; } int ans = 2, last = x[0]; for (int i = 1; i < n - 1; ++i) { if (x[i] - h[i] > last) { ans++; last = x[i]; } else if (x[i] + h[i] < x[i + 1]) { ans++; last = x[i] + h[i]; } else { last = x[i]; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 110000; const int oo = 0x3f3f3f3f; struct node { int x, h; } a[N]; int dp[N][3]; int main() { int n; while (scanf("%d", &n) != EOF) { int i; for (i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].h); memset(dp, 0, sizeof(dp)); dp[1][0] = dp[1][1] = 1; if (a[2].x - a[1].x > a[1].h) dp[1][2] = 1; for (i = 2; i <= n; i++) { int t = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])); dp[i][1] = t; if (a[i].x - a[i - 1].x > a[i].h) dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1; if (a[i].x - a[i - 1].x > a[i].h + a[i - 1].h) dp[i][0] = max(dp[i][0], dp[i - 1][2] + 1); if (i < n && a[i + 1].x - a[i].x > a[i].h) dp[i][2] = t + 1; if (i == n) dp[i][2] = t + 1; } printf("%d\n", max(dp[n][0], max(dp[n][1], dp[n][2]))); } return 0; }
#include <bits/stdc++.h> using namespace std; long long x[100005], h[100005], f[100005][3]; int main() { int n; while (cin >> n) { memset(f, 0, sizeof(f)); x[0] = -3e9; x[n + 1] = 3e9; for (int i = 1; i <= n; ++i) cin >> x[i] >> h[i]; for (int i = 1; i <= n; ++i) { f[i][0] = max(f[i - 1][2], max(f[i - 1][0], f[i - 1][1])); if (x[i] - h[i] > x[i - 1] + h[i - 1]) { f[i][1] = max(f[i][1], f[i - 1][2] + 1); f[i][1] = max(f[i][1], f[i - 1][1] + 1); f[i][1] = max(f[i][1], f[i - 1][0] + 1); } else if (x[i] - h[i] > x[i - 1]) { f[i][1] = max(f[i][1], f[i - 1][0] + 1); f[i][1] = max(f[i][1], f[i - 1][1] + 1); } if (x[i] + h[i] < x[i + 1]) { f[i][2] = max(f[i][2], f[i - 1][0] + 1); f[i][2] = max(f[i][2], f[i - 1][1] + 1); f[i][2] = max(f[i][2], f[i - 1][2] + 1); } } cout << max(f[n][2], max(f[n][1], f[n][0])) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long max(long long b, long long a) { if (b > a) return b; else return a; } long long min(long long b, long long a) { if (b < a) return b; else return a; } long long Abs(long long b) { return max(b, -b); } void print(vector<pair<long long, long long> > &v) { for (long long i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << endl; cout << endl; } void print(long long arr[], long long n) { for (long long i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } bool sortbysec(const pair<pair<long long, long long>, long long> &a, const pair<pair<long long, long long>, long long> &b) { return (a.first.second < b.first.second); } int32_t main() { long long n; cin >> n; long long x[n + 1], h[n + 1]; for (long long i = 0; i < n; i++) { cin >> x[i] >> h[i]; } x[n] = 4e9; long long m = x[0]; long long cnt = 1; for (long long i = 1; i < n; i++) { if (x[i] - m > h[i]) { m = x[i]; cnt++; } else if (x[i] + h[i] < x[i + 1]) { m = x[i] + h[i]; cnt++; } else m = x[i]; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int n, t[1 << 17], h[1 << 17], w; int dp(int i, int &l) { l = t[i]; if (i == n - 1) return 1; int r, m = dp(i + 1, r); if (!i || t[i] + h[i] < r) return m + 1; if (t[i] - h[i] <= t[i - 1]) return m; l = t[i] - h[i]; return m + 1; } int main(void) { scanf("%d", &n); for (int i(0); i < n; ++i) scanf("%d%d", &t[i], &h[i]); printf("%d\n", dp(0, w)); return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int MAX = 1e5; void sujho() { long long int n; cin >> n; long long int maxtree = 1; bool felltree = true; long long int x; long long int y; long long int lasty = 0; long long int lastx = 0; cin >> lastx >> lasty; for (long long int i = 1; i < n; i++) { cin >> x >> y; if (!felltree && lastx + lasty < x) { maxtree++; if (x - y > lastx + lasty) { maxtree++; felltree = true; } } else if (x - y > lastx && i < n - 1) { maxtree++; felltree = true; } else { felltree = false; } lastx = x; lasty = y; } if (!felltree) maxtree++; cout << maxtree << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); { sujho(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n = -1; cin >> n; long long int a = min((long long int)2, n); vector<array<long long int, 3>> t; int x, h; for (int i = 0; i < n; i++) { cin >> x >> h; t.push_back({x, h, 1}); } sort(t.begin(), t.end()); for (int i = 1; i < n - 1; i++) { if (t.at(i).at(2) && t.at(i).at(0) - t.at(i).at(1) > t.at(i - 1).at(0)) { a++; } else if (t.at(i).at(0) + t.at(i).at(1) < t.at(i + 1).at(0)) { a++; if (t.at(i).at(0) + t.at(i).at(1) >= t.at(i + 1).at(0) - t.at(i + 1).at(1)) { t.at(i + 1).at(2) = 0; } } } cout << a << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { if (y == 0) return x; else return gcd(y, x % y); } template <class T> T euclideanDistance(T x1, T x2, T y1, T y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> T digitSum(T n) { T sum = 0; while (n > 0) sum += n % 10, n /= 10; return sum; } const double INF = 1e+9; const double INFLL = 1e+18; const double EPS = 1e-9; const double PI = acos(-1); const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2}, {1, 2}, {2, -1}, {2, 1}, {-1, -2}, {1, -2}}; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const long long int MOD = 1000000000 + 7; int price[2000005] = {0, 1, 5, 8, 9, 10, 17, 17, 20, 24, 30}; int dp[2000005], lt[2000005], pos[2000005], ht[2000005], n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &pos[i], &ht[i]); } dp[1] = 1; lt[1] = pos[1]; for (int i = 2; i <= n; i++) { int temp = i == n ? INT_MAX : pos[i + 1]; if (pos[i] - lt[i - 1] > ht[i]) { dp[i] = dp[i - 1] + 1; lt[i] = pos[i]; } else if (pos[i] + ht[i] < temp) { dp[i] = dp[i - 1] + 1; lt[i] = pos[i] + ht[i]; } else { dp[i] = dp[i - 1]; lt[i] = max(pos[i], lt[i]); } } if (n == 2) printf("2\n"); else printf("%d\n", dp[n]); }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; long long x[n], h[n]; for (int i = 0; i < n; ++i) { cin >> x[i] >> h[i]; } long long ans = min(2, n); for (int i = 1; i + 1 < n; ++i) { if (x[i] - h[i] > x[i - 1]) { ans++; continue; } if (x[i] + h[i] < x[i + 1]) { ans++; x[i] += h[i]; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 0; int n, k, x, t; string s; vector<pair<int, int>> v; int main() { scanf("%d", &n); for (int i = 0, a, b; i < n; i++) { scanf("%d%d", &a, &b); v.push_back({a, b}); } int ans = min(n, 2); int prev = v[0].first; for (int i = 1; i < n - 1; i++) { if (v[i].first - v[i].second > prev) { ans++; prev = v[i].first; } else if (v[i].first + v[i].second < v[i + 1].first) { ans++; prev = v[i].first + v[i].second; } else { prev = v[i].first; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int d[100005], h[100005], n, dp[100005][3]; int fun(int idx, int dir) { if (idx == n) { return 0; } if (dp[idx][dir] != -1) { return dp[idx][dir]; } int &ret = dp[idx][dir]; if (dir != 2) { if (!idx || d[idx - 1] < d[idx] - h[idx]) ret = 1 + fun(idx + 1, 0); } else { if (d[idx - 1] + h[idx - 1] < d[idx] - h[idx]) { ret = 1 + fun(idx + 1, 0); } } ret = max(ret, fun(idx + 1, 1)); if ((idx == n - 1 || d[idx + 1] > h[idx] + d[idx])) { ret = max(ret, 1 + fun(idx + 1, 2)); } return ret; } int main() { memset(dp, -1, sizeof dp); cin >> n; for (int i = 0; i < n; i++) { cin >> d[i] >> h[i]; } cout << fun(0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count = 1, prev; vector<pair<int, int> > v; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; v.push_back({x, y}); } prev = v[0].first; for (int i = 1; i < n; i++) { if (i == n - 1) count++; else { int a = v[i].first; int b = v[i].second; if ((a - b) > prev) { count++; prev = a; } else if ((a + b) < v[i + 1].first) { prev = a + b; count++; } else prev = a; } } cout << count << "\n"; return 0; }
#include <bits/stdc++.h> int n, a[100010], b[100010], ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]); for (int i = 2; i < n; i++) if (a[i] - b[i] > a[i - 1]) ans++; else if (a[i] + b[i] < a[i + 1]) ans++, a[i] += b[i]; if (n == 1) puts("1"); else printf("%d\n", ans + 2); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int a[n][2], i; for (i = 0; i < n; i++) scanf("%d", &a[i][0]), scanf("%d", &a[i][1]); int cnt = 0; for (i = 1; i < n - 1; i++) { if (a[i][0] - a[i][1] > a[i - 1][0]) { cnt++; continue; } if (a[i][0] + a[i][1] < a[i + 1][0]) { cnt++; a[i][0] = a[i][0] + a[i][1]; continue; } } if (n >= 2) cout << cnt + 2 << endl; else if (n == 1) cout << cnt + 1 << endl; else cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, i, x[100005], h[100005], vis[100005], ans = 0; memset(vis, 0, sizeof(vis)); cin >> n; for (i = 0; i < n; i++) cin >> x[i] >> h[i]; vis[0] = 1; vis[n - 1] = 2; for (i = 1; i < n - 1; i++) { if (h[i] < x[i] - x[i - 1] && vis[i - 1] != 2) vis[i] = 1; else if (vis[i - 1] == 2 && h[i] + h[i - 1] < x[i] - x[i - 1]) vis[i] = 1; else if (h[i] < x[i + 1] - x[i]) vis[i] = 2; } for (i = 0; i < n; i++) if (vis[i]) ans++; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int loc[100005], hgt[100005]; int main() { int n, ans = 2; cin >> n; for (int i = 0; i < n; i++) cin >> loc[i] >> hgt[i]; for (int i = 1; i < n - 1; i++) { if (loc[i] - loc[i - 1] > hgt[i]) { ans++; } else if (loc[i + 1] - loc[i] > hgt[i]) { ans++; loc[i] += hgt[i]; } } if (n == 1) cout << 1; else cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, sum; cin >> n; int fill; int a[100000][2]; for (i = 0; i < n; i++) { cin >> a[i][0]; cin >> a[i][1]; } if (n == 1) { cout << 1; return 0; } if (n == 2) { cout << 2; return 0; } sum = 0; fill = 0; for (i = 1; i < n - 1; i++) { if (a[i][1] < (a[i][0] - a[i - 1][0] - fill)) { sum++; fill = 0; } else { if (a[i][1] < (a[i + 1][0] - a[i][0])) { sum++; fill = a[i][1]; } else { fill = 0; } } } sum += 2; cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } int main() { ios::sync_with_stdio(0); long n, i; long x[200000], h[200000]; cin >> n; for (i = 0; i < n; i += 1) { cin >> x[i]; cin >> h[i]; } if (n == 1) { cout << 1; return 0; } long cnt = 2; for (i = 1; i < n - 1; i += 1) { if (x[i - 1] < (x[i] - h[i])) { cnt += 1; } else if (x[i + 1] > (x[i] + h[i])) { cnt += 1; x[i] += h[i]; } } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int ans = 1; long long x[maxn], h[maxn]; int main() { long long n, frb; cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; x[n] = (long long)1000 * 1000 * 1000 * 1000; frb = x[0]; for (int i = 1; i < n; i++) { if (x[i] - h[i] > frb) frb = x[i], ans++; else { if (x[i] + h[i] >= x[i + 1]) { frb = x[i]; continue; } else { if (x[i] + h[i] < x[i + 1] - h[i + 1]) { ans++; frb = x[i] + h[i]; continue; } else { frb = x[i] + h[i]; ans++; continue; } } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int C[N], H[N], n; int main() { cin >> n; if (n <= 2) return cout << n << endl, 0; int ans = 2; for (int i = 0; i < n; ++i) cin >> C[i] >> H[i]; double lst = C[0]; for (int i = 1; i < n - 1; ++i) { if (C[i] - H[i] > lst) ans++, lst = C[i]; else if (C[i] + H[i] < C[i + 1]) ans++, lst = C[i] + H[i]; else lst = C[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<long long, long long> v[n]; for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; } long long mx = v[0].first; int cnt = min(2, n); for (int i = 1; i < n - 1; i++) { mx = max(v[i - 1].first, mx); if (v[i].first - v[i].second > mx) { mx = v[i].first; cnt++; } else if (v[i].first + v[i].second < v[i + 1].first) { mx = v[i].first + v[i].second; cnt++; } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 1; cin >> n; int a[n + 1], b[n]; a[n] = INT_MAX; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 1; i < n; i++) if (a[i] - a[i - 1] > b[i]) ans++; else if (a[i + 1] - a[i] > b[i]) a[i] += b[i], ans++; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; struct X { long long x, h; }; X ara[100005]; bool func(X a, X b) { return a.x < b.x; } int main() { long long n; scanf("%I64d", &n); for (long long i = 0; i < n; i++) { scanf("%I64d%I64d", &ara[i].x, &ara[i].h); } sort(ara, ara + n, func); long long c = 1; long long occup = ara[0].x; for (long long i = 1; i < n - 1; i++) { if (ara[i].x - ara[i].h > occup) { occup = ara[i].x; c++; } else if (ara[i].x + ara[i].h < ara[i + 1].x) { occup = ara[i].x + ara[i].h; c++; } else { occup = ara[i].x; } } if (n > 1) { c++; } printf("%I64d\n", c); }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<int, int>> a(n); for (auto& x : a) cin >> x.first >> x.second; vector<vector<int>> dp(n, vector<int>(3)); dp[0][0] = 0; dp[0][1] = 1; dp[0][2] = (a[0].first + a[0].second < a[1].first); for (int i = 1; i < n; ++i) { dp[i][0] = max(max(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]); if (a[i].first - a[i].second > a[i - 1].first) { dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1; if (a[i - 1].first + a[i - 1].second < a[i].first - a[i].second) { dp[i][1] = max(dp[i][1], dp[i - 1][2] + 1); } } if (i == n - 1 || a[i].first + a[i].second < a[i + 1].first) { dp[i][2] = dp[i][0] + 1; } } cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]); }
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; using namespace std::chrono; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, y; cin >> n; long long int x[n], h[n]; for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; long long int dp[n][3]; memset(dp, 0, sizeof(dp)); dp[0][0] = dp[0][2] = 1; dp[0][1] = 0; for (int i = 1; i < n; i++) { if (x[i] - h[i] > x[i - 1]) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1; if (x[i - 1] + h[i - 1] < x[i] - h[i]) dp[i][0] = max(dp[i][0], dp[i - 1][2] + 1); } dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]); if (x[i - 1] + h[i - 1] < x[i]) dp[i][1] = max(dp[i][1], dp[i - 1][2]); if (i == n - 1) dp[i][2] = dp[i][1] + 1; else if (x[i] + h[i] < x[i + 1]) dp[i][2] = dp[i][1] + 1; } cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x[100005] = {0}, h[100005] = {0}; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } int count = 2; for (int i = 1; i < n - 1; i++) { if (x[i] - x[i - 1] > h[i]) count++; else if (x[i + 1] - x[i] > h[i]) { count++; x[i] = x[i] + h[i]; } } if (n == 1) cout << 1; else cout << count; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); long long n, i; cin >> n; long long x[n], h[n]; for (i = 0; i < n; i++) cin >> x[i] >> h[i]; long long c = min(2LL, n); for (i = 1; i < n - 1; i++) { if (x[i] - x[i - 1] > h[i]) c++; else if (x[i + 1] - x[i] > h[i]) { c++; x[i] = x[i] + h[i]; } } cout << c << endl; }
#include <bits/stdc++.h> using namespace std; map<int, int> mm; struct s { int x, h; } a[100005]; bool cmp(const s& xx, const s& yy) { return xx.h < yy.h; } int hehe[300005], k, c[500005]; int lowbit(int t) { return t & (-t); } void insert(int x, int d) { while (x <= k) { c[x] += d; x += lowbit(x); } } int get_sum(int x) { int sum = 0; while (x > 0) { sum += c[x]; x -= lowbit(x); } return sum; } int main() { int n; scanf("%d", &n); k = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].x, &a[i].h); hehe[++k] = a[i].x; hehe[++k] = max(1, a[i].x - a[i].h); hehe[++k] = a[i].x + a[i].h; } sort(hehe + 1, hehe + k + 1); for (int i = 1; i <= k; i++) mm[hehe[i]] = i; for (int i = 0; i < n; i++) { insert(mm[a[i].x], 1); } int ans = 0; for (int i = 0; i < n; i++) { int L = max(a[i].x - a[i].h, 1); int R = a[i].x + a[i].h; int suml = get_sum(mm[a[i].x] - 1) - get_sum(mm[L] - 1); int sumr = get_sum(mm[R]) - get_sum(mm[a[i].x]); if (suml == 0 || sumr == 0) ans++; if (sumr == 0 && suml != 0) { insert(mm[R], 1); } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, w = 2; cin >> n; if (n == 1) return cout << 1, 0; long long coor[2][n]; long long hight[n]; for (long long i = 0; i < n; i++) { cin >> coor[0][i] >> hight[i]; coor[1][i] = coor[0][i]; } for (long long i = 1; i < n - 1; i++) { if (coor[0][i] - hight[i] > coor[1][i - 1]) { coor[0][i] -= hight[i]; w++; } else if (coor[1][i] + hight[i] < coor[0][i + 1]) { coor[1][i] += hight[i]; w++; } } cout << w; return 0; }
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; long long IM = 1e17; void PV(vector<long long> v) { for (long long i = 0; i < v.size(); i++) cout << v[i] << " "; cout << "\n"; } void PA(long long v[], long long n) { for (long long i = 0; i < n; i++) cout << v[i] << " "; cout << "\n"; } void IN(long long a[], long long n) { for (long long i = 0; i < n; i++) cin >> a[i]; } inline void PTN(long long n = 1, long long a = 0, long long b = 0, long long c = 0) { if (n--) cout << a << " "; if (n--) cout << b << " "; if (n--) cout << c << " "; cout << "\n"; } inline void open() {} long long maxx(long long x, long long y, long long z) { return max(x, max(y, z)); } long long dp[100005][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); open(); { long long n; cin >> n; vector<pair<long long, long long> > v; long long i, j, k, l, x, y; for (i = 0; i < n; i++) { cin >> x >> y; v.push_back({x, y}); } v.push_back({IM, IM}); long long ans = 0; dp[0][1] = 1; if (v[0].first + v[0].second < v[1].first) dp[0][2] = 1; for (i = 1; i < n; i++) { dp[i][1] = dp[i - 1][1]; dp[i][2] = dp[i - 1][2]; dp[i][0] = maxx(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]); if (v[i - 1].first < v[i].first - v[i].second) dp[i][1] = max(dp[i][1], dp[i - 1][0]) + 1; if (v[i - 1].first + v[i - 1].second < v[i].first - v[i].second) dp[i][1] = dp[i][0] + 1; if (v[i].first + v[i].second < v[i + 1].first) dp[i][2] = dp[i][0] + 1; ans = maxx(dp[i][0], dp[i][1], dp[i][2]); } ans = max(ans, 1ll); cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = acos((long double)-1.0); const double eps = (double)1e-9; const int inf = (int)1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long int x[n], h[n]; for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } long long int l, cnt = 0; for (int i = 0; i < n; i++) { if (i == 0) { cnt++; l = x[i]; } else if (i == n - 1) { cnt++; } else if (x[i] - h[i] > l) { cnt++; l = x[i]; } else if (x[i] + h[i] < x[i + 1]) { cnt++; l = x[i] + h[i]; } else l = x[i]; } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); vector<int> indices(n); for (int i = 0; i < n; i++) { int ind, height; cin >> ind >> height; arr[i] = ind; indices[i] = height; } int past = 0; int ans = 0; int edge; for (int i = 0; i < n; i++) { if (i == 0 || i == n - 1) { ans++; } else { if (arr[i] - indices[i] > arr[i - 1]) { ans++; } else { if (arr[i] + indices[i] < arr[i + 1]) { ans++; arr[i] = arr[i] + indices[i]; } } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005], c[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(c, 0, sizeof c); int n, count = 2; cin >> n; if (n == 1) { cout << 1; } else { for (int i = 1; i < n + 1; i++) { cin >> a[i] >> b[i]; } c[1] = 1; for (int i = 2; i < n; i++) { if (a[i] - a[i - 1] > b[i]) { c[i] = 1; count++; } else if (a[i + 1] - a[i] > b[i] && c[i] != 1) { c[i] = -1; count++; a[i] += b[i]; } } cout << count; } }
#include <bits/stdc++.h> using namespace std; struct node { int i, l; } tree[101000]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> tree[i].i >> tree[i].l; } if (n == 1 || n == 2) cout << n << endl; else { int flag = 2; for (int i = 1; i < n - 1; i++) { if (tree[i].i - tree[i].l > tree[i - 1].i) { flag++; } else if (tree[i].i + tree[i].l < tree[i + 1].i) { flag++; tree[i].i += tree[i].l; } } cout << flag << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int prevx, prevh, x, h, nextx, nexth; cin >> prevx >> prevh; if (n == 1) { cout << "1"; return 0; } int count = 1; int l = 1, r = 0; cin >> x >> h; if (n == 2) { cout << "2"; return 0; } n = n - 2; while (n--) { cin >> nextx >> nexth; if (h < x - prevx && r != 1) { count++; } else if (h + prevh < x - prevx) { count++; r = 0; } else if (h < nextx - x) { count++; r = 1; } else { r = 0; } prevx = x; prevh = h; x = nextx; h = nexth; } count++; cout << count; }
#include <bits/stdc++.h> using namespace std; const int S = 100010; int x[S], h[S]; int result = 2; int main() { int n; cin >> n; if (n == 1) { cout << 1; return 0; } for (int i = 0; i < n; i++) { cin >> x[i] >> h[i]; } int left = x[0]; for (int i = 1; i < n - 1; i++) { if (left < (x[i] - h[i])) { result++; left = x[i]; } else if ((x[i] + h[i]) < x[i + 1]) { result++; left = x[i] + h[i]; } else { left = x[i]; } } cout << result; return 0; }
#include <bits/stdc++.h> using namespace std; long long int n = 0, x[200000], h[200000], m = 0, su = 0; int main() { cin >> n; x[n + 1] = 5e9; for (int i = 1; i <= n; i++) { cin >> x[i] >> h[i]; } m = x[1]; su++; for (int i = 2; i <= n; i++) { if (x[i] - h[i] > m) { su++; m = x[i]; } else if (x[i] + h[i] < x[i + 1]) { su++; m = h[i] + x[i]; } else { m = x[i]; } } cout << su; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> mp; int n, a, b, i; cin >> n; int ans; n >= 2 ? ans = 2 : ans = n; for (i = 0; i < n; i++) { cin >> a >> b; mp[a] = b; } map<int, int>::iterator it, temp; it = mp.begin(); it++; temp = it; for (i = 1; i < n - 1; i++) { temp++; a = it->first; b = it->second; if (mp.lower_bound(a - b) == it) { ans++; } else if (a + b < temp->first) { ans++; mp[a + b] = 1; it++; } it++; temp = it; } cout << ans; }
#include <bits/stdc++.h> using namespace std; long long int w[100001]; int main() { long long int n, i, a[100001][2], c = 1, z; cin >> n; for (i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } z = a[0][0]; for (i = 1; i < n - 1; i++) { if ((a[i][0] - z) > a[i][1]) { c++; z = a[i][0]; } else if (a[i + 1][0] - a[i][0] > a[i][1]) { c++; z = a[i][0] + a[i][1]; } else z = a[i][0]; } if (n > 1) c++; cout << c; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c = 2, n1, i; vector<pair<long long int, long long int> > x; scanf("%lld", &n1); n = n1; while (n--) { scanf("%lld%lld", &a, &b); x.push_back(make_pair(a, b)); } if (n1 == 1) { printf("1\n"); return 0; } for (i = 1; i < x.size() - 1; i++) { if (x[i].first - x[i].second > x[i - 1].first) { c++; } else if (x[i].first + x[i].second < x[i + 1].first) { c++; x[i].first += x[i].second; } } printf("%lld\n", c); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; unordered_map<pair<int, int>, int, hash_pair> map_with_pair{}; priority_queue<int, vector<int>, greater<int> > pq_desc; int n; long long int maxTreesFell(long long int *x, long long int *h) { long long int ans = 1; if (n >= 2) ans = 2; int i = 1; while (i < n - 1) { long long int left = x[i] - h[i]; long long int right = x[i] + h[i]; if (x[i] > x[i - 1] && left > x[i - 1]) { ans++; } else if (x[i] > x[i - 1] && right < x[i + 1]) { x[i] = right; ans++; } i++; } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; long long int x[n], h[n]; for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; cout << maxTreesFell(x, h) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 28; const long long LINF = 1ll << 61; long long n, pos, ans; pair<long long, long long> a[100111]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1, a + 1 + n); pos = -LINF; for (int i = 1; i <= n; i++) { if (a[i].first - a[i].second > pos && (i == 1 || a[i].first - a[i].second > a[i - 1].first)) ans++, pos = a[i].first; if (a[i].first > pos && (i == n || a[i].first + a[i].second < a[i + 1].first)) ans++, pos = a[i].first + a[i].second; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[100005]; int h[100005]; int dp[100005][3]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> h[i]; } for (int i = n; i >= 1; i--) { if (i == 1 || a[i - 1] < a[i] - h[i]) { if (h[i + 1] >= a[i + 1] - a[i]) dp[i][1] = max(1 + dp[i + 1][0], 1 + dp[i + 1][2]); else dp[i][1] = 1 + dp[i + 1][1]; } else dp[i][1] = -1000000000; if (i == n || a[i + 1] > a[i] + h[i]) { if (a[i + 1] - h[i + 1] > a[i] + h[i]) dp[i][2] = 1 + dp[i + 1][1]; else dp[i][2] = max(1 + dp[i + 1][0], 1 + dp[i + 1][2]); } else dp[i][2] = -1000000000; if (a[i] < a[i + 1] - h[i + 1]) dp[i][0] = dp[i + 1][1]; else dp[i][0] = max(dp[i + 1][0], dp[i + 1][2]); } cout << dp[1][1]; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long mx = 2e7; vector<bool> pr(mx, 1); void sv() { pr[1] = 0; for (long long n = 2; n * n <= mx; n++) { if (pr[n]) { for (long long k = 2 * n; k < mx; k += n) pr[k] = 0; } } } long long bit[mx]; void up(long long ind, long long vl) { while (ind < mx) { bit[ind] += vl; ind += ind & (-ind); } } long long qr(long long ind) { long long res = 0; while (ind) { res += bit[ind]; ind -= ind & (-ind); } return res; } void solve() { long long x; scanf("%lld", &(x)); vector<pair<long long, long long> > s(x); for (int n = 0; n < x; n++) scanf("%lld", &(s[n].first)), scanf("%lld", &(s[n].second)); if (x == 1) { printf("%lld\n", (x)); return; } long long res = 2; long long prv = s[0].first; for (long long n = 1; n < x - 1; n++) { long long a = s[n].first - s[n].second; long long b = s[n].first + s[n].second; if (a > prv) { res++; prv = s[n].first; continue; } else if (b < s[n + 1].first) { res++; prv = b; continue; } prv = s[n].first; } printf("%lld\n", (res)); } int main() { solve(); }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; while (cin >> n) { vector<long long int> height(n + 5); vector<long long int> left(n + 5); vector<long long int> right(n + 5); long long int x, y, h, a; for (a = 1; a <= n; a++) { cin >> x >> h; height[a] = h; if (a != 1) left[a] = x - y - 1; right[a - 1] = left[a]; y = x; } long long int cnt = n; for (a = 2; a < n; a++) { if (height[a] > left[a]) { if (height[a] <= right[a]) left[a + 1] = left[a + 1] - height[a]; else cnt--; } } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long n; long long ans; long long x[100010]; long long h[100010]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> h[i]; } if (n != 1) ans++; ans++; for (int i = 2; i < n; i++) { if (x[i] - h[i] > x[i - 1]) ans++; else { if (x[i] + h[i] < x[i + 1]) { x[i] = x[i] + h[i]; ans++; } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; if (n == 1) { cout << 1; return 0; } pair<long long, long long> a[n]; for (int i = 0; i < n; ++i) { cin >> a[i].first >> a[i].second; } long long ans = 2; a[0].second = a[0].first; a[n - 1].second = a[n - 1].first; for (long long i = 1; i < n - 1; i++) { if (a[i].first - a[i].second > max(a[i - 1].first, a[i - 1].second)) { ans++; a[i].second = a[i].first - a[i].second; } else if (a[i].first + a[i].second < a[i + 1].first) { ans++; a[i].second = a[i].first + a[i].second; } else { a[i].second = a[i].first; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 2; cin >> n; int arr[100005], brr[100005]; for (int i = 0; i < n; i++) { cin >> arr[i] >> brr[i]; } arr[n] = INT_MAX; for (int i = 1; i < n - 1; i++) { if (arr[i] - arr[i - 1] > brr[i]) { count++; } else if (arr[i + 1] - arr[i] > brr[i]) { arr[i] += brr[i]; count++; } } if (n == 1) cout << "1"; else cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; long long power(long long a, long long b, long long m = MOD) { long long ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % m; a = (a * a) % m; b >>= 1; } return ans; } long long dir[] = {-1, 0, 1, 0, -1}; long long dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; long long dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; void solve() { long long i, ans = 2, n; cin >> n; vector<long long> x(n), h(n); for (i = 0; i < n; i++) cin >> x[i] >> h[i]; if (n <= 2) { cout << n << "\n"; return; } for (i = 1; i < n - 1; i++) { if (x[i] - h[i] > x[i - 1]) ans++; else if (x[i] + h[i] < x[i + 1]) { ans++; x[i] = x[i] + h[i]; } } cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; t = 1; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int a[100002]; int h[100002]; int d[100002]; int df(int i, int k, int n) { if (i >= n - 1) return 0; if (d[i] != -1) return d[i]; int y = max(a[i - 1], k); int x = max(a[i + 1], k); int a1 = 0, a2 = 0, a3 = 0; if (y < (a[i] - h[i])) a1 = 1 + df(i + 1, a[i], n); if (x > (a[i] + h[i])) a2 = 1 + df(i + 1, a[i] + h[i], n); a3 = df(i + 1, a[i], n); return d[i] = max(a3, max(a1, a2)); } int main() { int n; cin >> n; memset(d, -1, sizeof d); for (int i = 0; i < n; i++) { cin >> a[i] >> h[i]; } if (n > 1) cout << 2 + df(1, 0, n); else cout << 1 << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int i, j, k, m, n, last, ans; struct wood { int p, l; } w[maxn]; inline int cmp(wood a, wood b) { return a.p < b.p; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d%d", &w[i].p, &w[i].l); sort(w + 1, w + 1 + n, cmp); if (n == 1) { puts("1"); return 0; } ans = 2, last = w[1].p; for (i = 2; i < n; i++) { if (w[i].p - w[i].l > last) ans++, last = w[i].p; else if (w[i].p + w[i].l < w[i + 1].p) ans++, last = w[i].p + w[i].l; else last = w[i].p; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; if (n <= 2) { cout << n; return 0; } int x[n + 10], h[n + 10]; for (int i = 1; i <= n; ++i) cin >> x[i] >> h[i]; int ans = 2; int i = 2; while (i < n) { if (x[i] - h[i] > x[i - 1]) ++ans; else if (x[i] + h[i] < x[i + 1]) { x[i] += h[i]; ++ans; } ++i; } cout << ans; return 0; }
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); if (n == 1) { printf("%d", 1); return 0; } int x[100000], h[100000]; for (int i = 0; i < n; ++i) scanf("%d %d", &x[i], &h[i]); int count = 2; int left = x[0]; for (int i = 1; i < n - 1; ++i) { if (left < x[i] - h[i]) { left = x[i]; ++count; } else if (x[i] + h[i] < x[i + 1]) { left = x[i] + h[i]; ++count; } else { left = x[i]; } } printf("%d", count); return 0; }
#include <bits/stdc++.h> using namespace std; long long tc, n, a[100001], b[100001], cnt, last; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; } last = a[0]; cnt = 1; for (int i = 1; i < n - 1; ++i) { if (a[i] > (b[i] + last)) { cnt++; last = a[i]; } else if ((i + 1) < n && (a[i] + b[i]) < a[i + 1]) { cnt++; last = a[i] + b[i]; } else { last = a[i]; } } if (n > 1) cnt++; cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n), v(n); for (int i = 0; i < n; ++i) cin >> x[i] >> v[i]; int ans = min(n, 2); int pr = x[0]; for (int i = 1; i < n - 1; i++) { if (x[i] - v[i] > pr) { ans++; pr = x[i]; } else { if (x[i] + v[i] < x[i + 1]) { pr = x[i] + v[i]; ans++; } else pr = x[i]; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; map<long long, long long>::iterator itr; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void ans() { long long num; cin >> num; vector<pair<long long, long long>> A; for (long long i = 0; i < num; i++) { long long x, y; cin >> x >> y; A.push_back(make_pair(x, y)); } sort(A.begin(), A.end()); if (num <= 2) { cout << num; return; } long long c = 2; for (long long i = 1; i < num - 1; i++) { if (A[i].first - A[i - 1].first > A[i].second) c++; else if (A[i + 1].first - A[i].first > A[i].second) { c++; A[i].first += A[i].second; } } cout << c; } int32_t main() { c_p_c(); ans(); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 3; int n, x[MAXN], h[MAXN]; int memo[MAXN][3]; int fn(int idx, int dir) { if (idx >= n) return 0; int &rf = memo[idx][dir]; if (rf != -1) return rf; int occupiedUpto = (dir <= 1) ? x[idx] : x[idx] + h[idx]; rf = fn(idx + 1, 0); if (occupiedUpto < x[idx + 1] - h[idx + 1]) rf = max(rf, 1 + fn(idx + 1, 1)); if (idx + 2 < n and x[idx + 1] + h[idx + 1] < x[idx + 2]) rf = max(rf, 1 + fn(idx + 1, 2)); if (idx + 2 >= n) rf = max(rf, 1 + fn(idx + 1, 2)); return rf; } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d %d", x + i, h + i); for (int i = 0; i < n; ++i) memo[i][0] = memo[i][1] = memo[i][2] = -1; printf("%d\n", max(fn(0, 0), max(fn(0, 1), fn(0, 2)))); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, i, c = 0; struct tree { long long p; long long h; }; tree a[100000]; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a[i].p >> a[i].h; } if (n > 1) c = 2; else c = 1; for (i = 1; i < n - 1; i++) { if (a[i].p - a[i].h > a[i - 1].p) c++; else if (a[i].p + a[i].h < a[i + 1].p) { c++; a[i].p += a[i].h; } } cout << c; }
#include <bits/stdc++.h> using namespace std; int n, dp[100005][3]; pair<int, int> t[100005]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> t[i].first >> t[i].second; sort(t + 1, t + n + 1); for (int i = 1; i <= n; i++) { dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])); if (t[i - 1].first < t[i].first - t[i].second || i == 1) dp[i][1] = 1 + max(dp[i - 1][0], dp[i - 1][1]); if (t[i - 1].first + t[i - 1].second < t[i].first - t[i].second) dp[i][1] = max(dp[i][1], 1 + dp[i - 1][2]); if (t[i + 1].first > t[i].first + t[i].second || i == n) dp[i][2] = 1 + dp[i][0]; } int ans = max(dp[n][0], max(dp[n][1], dp[n][2])); cout << ans; }
#include <bits/stdc++.h> using namespace std; int n, x[105000], h[105000]; int ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &h[i]); x[0] = -INT_MAX; x[n + 1] = INT_MAX; for (int i = 1; i <= n; ++i) { if (x[i] - h[i] > x[i - 1]) ++ans; else if (x[i] + h[i] < x[i + 1]) { ++ans; x[i] += h[i]; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const int N = 1e6 + 7; int n; int x[N], h[N]; int dp[100001][3]; int getAns(int idx, int con) { if (idx > n) return 0; if (dp[idx][con] != -1) return dp[idx][con]; int ans = 0; int pos; if (con == 0) pos = x[idx - 1]; if (con == 1) pos = x[idx - 1]; if (con == 2) pos = x[idx - 1] + h[idx - 1]; ans = max(ans, getAns(idx + 1, 0)); if (x[idx] - h[idx] > pos) ans = max(ans, getAns(idx + 1, 1) + 1); if (x[idx] + h[idx] < x[idx + 1]) ans = max(ans, getAns(idx + 1, 2) + 1); return dp[idx][con] = ans; } int main() { cin >> n; for (long long i = 1; i < (int)n + 1; i++) cin >> x[i] >> h[i]; x[0] = INT_MIN, h[0] = INT_MIN; x[n + 1] = INT_MAX; memset(dp, -1, sizeof dp); cout << getAns(1, 0); return 0; }
#include <bits/stdc++.h> using namespace std; int p1 = -1000000001; int p2 = -1000000001; int n; int q1, h, q2, a, b, c1, c2; int main() { cin >> n; for (; n; n--) { cin >> q1 >> h; q2 = q1 + h; a = -1; if (q1 - h > p1) a = max(a, c1 + 1); if (q1 > p1) a = max(a, c1); if (q1 - h > p2) a = max(a, c2 + 1); if (q1 > p2) a = max(a, c2); b = -1; if (q1 > p1) b = max(b, c1 + 1); if (q1 > p2) b = max(b, c2 + 1); p1 = q1; c1 = a; p2 = q2; c2 = b; } cout << max(c1, c2); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int coord; int length; }; int main() { int n; cin >> n; if (n < 3) { cout << n << endl; return 0; } int sum = 1; point p1, p2, p3; cin >> p1.coord >> p1.length; cin >> p2.coord >> p2.length; cin >> p3.coord >> p3.length; for (int i = 0; i < n - 2; ++i) { if (p2.coord - p1.coord > p2.length) { sum++; } else if (p3.coord - p2.coord > p2.length) { sum++; p2.coord += p2.length; } p1 = p2; p2 = p3; if (i != n - 3) cin >> p3.coord >> p3.length; } cout << sum + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans = 2, tmp; cin >> n; if (n == 1) { cout << 1; } else { long long x[n], h[n]; for (int k = 0; k < n; k++) cin >> x[k] >> h[k]; for (int k = 1; k < n - 1; k++) { if (x[k] - h[k] > x[k - 1]) { ans++; } else if (x[k] + h[k] < x[k + 1]) { ans++; x[k] += h[k]; } } cout << ans; } }
#include <bits/stdc++.h> using namespace std; long long int n, xc[300001], h[300001], dp[300001][3]; int solve(int pos, int last, int las) { if (pos == n) return 1; if (dp[pos][last] != -1) return dp[pos][last]; if (las < xc[pos] - h[pos]) { return dp[pos][last] = max(1 + solve(pos + 1, 0, xc[pos]), solve(pos + 1, 1, xc[pos])); } else { int ans = solve(pos + 1, 1, xc[pos]); if (xc[pos + 1] > xc[pos] + h[pos]) ans = max(ans, 1 + solve(pos + 1, 2, xc[pos] + h[pos])); return dp[pos][last] = ans; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= n; ++i) cin >> xc[i] >> h[i]; if (n <= 2) { cout << n; return 0; } int ans = 1 + solve(2, 0, xc[1]); cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, ans = 1; cin >> n; vector<int> x(n + 1, 0), h(n + 1, 0); for (int i = 0; i < n; i++) cin >> x[i] >> h[i]; x[n] = INT_MAX; for (int i = 1; i < n; i++) { if (x[i] - x[i - 1] > h[i]) { ans++; } else if (x[i + 1] - x[i] > h[i]) { x[i] += h[i]; ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const long long INF = 10000000000000; const double long EPS = 1e-8; int main() { cout.setf(ios::fixed); cout.precision(0); int n; cin >> n; vector<long long> kuda(n); vector<pair<long long, long long> > coor(n); for (int i = 0; i < n; ++i) { cin >> coor[i].first >> coor[i].second; } sort(coor.begin(), coor.end()); long long amount = 2; if (n < 2) amount = n; kuda[0] = 0; for (int i = 1; i < n - 1; ++i) { if (kuda[i - 1] == 1) { if (coor[i].first - coor[i].second > coor[i - 1].first + coor[i - 1].second) { kuda[i] = 0; amount++; } else if (coor[i].first + coor[i].second < coor[i + 1].first) { kuda[i] = 1; amount++; } else kuda[i] = 0; } else { if (coor[i].first - coor[i].second > coor[i - 1].first) { kuda[i] = 0; amount++; } else if (coor[i].first + coor[i].second < coor[i + 1].first) { kuda[i] = 1; amount++; } else kuda[i] = 0; } } cout << amount << endl; return 0; }
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[100009]; int main() { int a, san = 0, last = 0; cin >> a; for (int i = 0; i < a; i++) cin >> arr[i].first >> arr[i].second; for (int i = 0; i < a; i++) { if (i == 0 or i == a - 1) { if (i == 0) last = arr[i].first, san++; else if (i == a - 1 and arr[i].first > last) san++; } else { if (arr[i].first - arr[i].second > last and arr[i - 1].first < arr[i].first - arr[i].second) { san++; last = arr[i].first; } else if (arr[i].first + arr[i].second < arr[i + 1].first and arr[i].first > last) { san++; last = arr[i].first + arr[i].second; } } } cout << san << endl; return 0; }
#include <bits/stdc++.h> struct P { int x, h; } a[100010]; bool vis[100010]; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].h); a[0].x = -1000000007; a[0].h = 0; a[n + 1].x = 1000000007 * 2; a[n + 1].h = 0; memset(vis, true, sizeof(vis)); for (int i = 0; i <= n; i++) { int j = i + 1; if (i != 0 && vis[i] && ((a[i].x + a[i].h) < a[j].x)) { ans++; a[i].x += a[i].h; vis[i] = false; } if (j != n + 1 && vis[j] && ((a[j].x - a[j].h) > a[i].x)) { ans++; vis[j] = false; } } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; long long int x[n], h[n]; for (i = 0; i < n; i++) { scanf("%lld%lld", &x[i], &h[i]); } if (n == 1) { cout << 1 << endl; return 0; } int ans = 2; bool fl = true; for (i = 1; i < n - 1; i++) { if (fl) { if ((x[i] - h[i]) > x[i - 1]) { ans++; } else { fl = false; } } else { if ((x[i - 1] + h[i - 1] + h[i]) < x[i]) { ans += 2; fl = true; } else if ((x[i - 1] + h[i - 1]) < x[i]) { ans++; } else if ((x[i] - h[i]) > x[i - 1]) { ans++; fl = true; } } } if (!fl) { if ((x[i - 1] + h[i - 1]) < x[i]) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, x[100005], h[100005]; long long dp[100005][3]; long long go(long long i, long long pichla) { if (i > n) return 0; if (dp[i][pichla] != -1) return dp[i][pichla]; long long ans = go(i + 1, 0); long long add = 0; if (pichla == 2) add = h[i - 1]; if (x[i] - h[i] > x[i - 1] + add) ans = max(ans, 1 + go(i + 1, 1)); if (x[i] + h[i] < x[i + 1]) ans = max(ans, 1 + go(i + 1, 2)); return dp[i][pichla] = ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long i, j; memset(dp, -1, sizeof dp); cin >> n; for (i = 1; i <= n; i++) { cin >> x[i] >> h[i]; } x[0] = -1e17; h[0] = 0; x[n + 1] = 1e17; h[n + 1] = 0; cout << go(1, 0); return 0; }
#include <bits/stdc++.h> using namespace std; int v[100001], h[100005], d[100005]; int main() { int n, i; cin >> n; int cnt = 2; for (i = 1; i <= n; i++) { cin >> v[i] >> h[i]; } for (i = 2; i <= n; i++) { d[i] = v[i] - v[i - 1]; } for (i = 2; i < n; i++) { if (h[i] < d[i]) { cnt++; } else if (h[i] >= d[i] && h[i] < d[i + 1]) { cnt++; d[i + 1] -= h[i]; } } if (n == 1) { cout << "1"; return 0; } else cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long read() { long long s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * f; } inline void print(long long *f, long long len) { for (long long i = 0; i < len; i++) printf("%lld ", f[i]); puts(""); } long long x[202020], y[202020]; signed main() { n = read(); for (long long i = 1, iend = n; i <= iend; ++i) x[i] = read(), y[i] = read(); x[n + 1] = 103134134134; long long ans = 0; for (long long i = 2, iend = n; i <= iend; ++i) { if (x[i] - x[i - 1] > y[i]) ++ans; else if (x[i + 1] - x[i] > y[i]) x[i] += y[i], ++ans; } cout << ans + 1; }