intmain(){ scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); int k = a[n - 1] - a[0]; printf("%d", k + 1 - n); return0; }
intmain(){ scanf("%d%d%d", &n, &m, &d); for (int i = 0, x; i < n; i++) scanf("%d", &x), s.insert(make_pair(x, i)); int day = 0; while (!s.empty()){ day++; auto it = s.begin(); while (it != s.end()){ ans[it->second] = day; int x = it->first; s.erase(it); it = s.lower_bound(make_pair(x + d + 1, 0)); } } printf("%d\n", day); for (int i = 0; i < n; i++) printf("%d ", ans[i]); return0; }
intmain(){ scanf("%d%d", &n, &h); for (int i = 0; i < n; i++) scanf("%d%d", l + i, r + i); if (n == 1){ printf("%d", r[0] - l[0] + h); return0; } for (int i = n - 2; i >= 0; i--) dt[i] = dt[i + 1] - l[i + 1] + r[i]; for (int i = n - 1; i >= 0; i--) len[i] = len[i + 1] + r[i] - l[i]; int ans = -inf; for (int i = 0; i < n; i++){ if (h > -dt[i]) ans = max(ans, h + len[i]); else { int k = lower_bound(dt, dt + n, dt[i] + h) - dt; ans = max(ans, h + len[i] - len[k]); } } printf("%d", ans); return0; }