intmain(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> l >> a; int ans = 0, tot = 0; for (int i = 0; i < n; i++){ cin >> s[i] >> len[i]; } s[n] = l; while (tot + a <= s[0]) ans++, tot += a; for (int i = 0; i < n; i++){ tot = s[i] + len[i]; while (tot + a <= s[i + 1]) ans++, tot += a; } while (tot + a <= l) ans++, tot += a; cout << ans; return0; }
intgcd(int a, int b){return b ? gcd(b, a % b) : a;}
int n, a[maxn];
voiddfs(int n, int base){ if (n == 1){ printf("%d", base); } if (n == 2){ printf("%d %d", base, base * 2); } if (n == 3){ printf("%d %d %d", base, base, base * 3); } if (n <= 3) return; for (int i = 1; i <= n; i += 2) printf("%d ", base); dfs(n / 2, base * 2); }
intmain(){ scanf("%d", &n); if (n == 1) returnputs("1"), 0; if (n == 2) returnputs("1 2"), 0; if (n == 3) returnputs("1 1 3"), 0; dfs(n, 1); return0; }
boolcheck(double x){ double l = -1e14, r = 1e14; for (int i = 0; i < n; i++){ double d = 2.0 * x * b[i] - 1.0 * b[i] * b[i]; if (d < eps) return0; l = max(l, 1.0 * a[i] - sqrt(d)); r = min(r, 1.0 * a[i] + sqrt(d)); } return r - l > eps; }
intmain(){ scanf("%d", &n); int flag = 0, cnt = 0; for (int i = 0; i < n; i++) { scanf("%d%d", a + i, b + i); if (!flag){ if (b[i] > 0) flag = 1; elseif (b[i] < 0) flag = -1; else { if (cnt) returnputs("-1"), 0; else cnt = 1; } } else { if (b[i] * flag < 0) returnputs("-1"), 0; } b[i] = abs(b[i]); } double l = -1e14, r = 1e14; for (int i = 0; i < 100; i++){ double m = (l + r) / 2; if (check(m)) r = m; else l = m; } printf("%.8lf", l); return0; }
vector<int> edge[maxn]; int n, l, w[maxn], ans, dep[maxn], tot, top[maxn], id[maxn], path[maxn]; ll s, pre[maxn];
intget(int u, int d){ int l = max(1, d - ::l + 1), r = d, ans = u; while (l <= r) { int m = (l + r) >> 1; if (pre[d] - pre[m - 1] <= s) r = m - 1, ans = id[m]; else l = m + 1; } return ans; } voiddfs(int u, int f){ dep[u] = dep[f] + 1; tot++; pre[tot] = pre[tot - 1] + w[u]; id[tot] = u; top[u] = get(u, tot); for (int& v: edge[u]) { dfs(v, u); } tot--; } intdfs(int u){ int r = -1; for (int& v: edge[u]) { int t = dfs(v); if (t == v) continue; if (r == -1 || dep[t] < dep[r]) r = t; } if (r != -1) return r; ans++; return top[u]; }
intmain(){ scanf("%d%d%I64d", &n, &l, &s); for (int i = 1; i <= n; i++) { scanf("%d", w + i); if (w[i] > s) returnputs("-1"), 0; } for (int i = 2, x; i <= n; i++) scanf("%d", &x), edge[x].push_back(i); dfs(1, 0); dfs(1); cout << ans << endl; return0; }