boolcheck(longlong x){ memset(d, 0, sizeof d); for (int i = 1; i <= m; i++) { if (b[i] < x) { d[1] += x - b[i] + 1; d[2] -= x - b[i]; d[b[i] + 1]--; } else { d[b[i] - x + 1]++; d[b[i] + 1]--; }
d[b[i] + 1]--; if (b[i] + x <= n) d[b[i] + x + 1]++; } for (int i = 1; i <= n; i++) d[i] += d[i - 1]; for (int i = 1; i <= n; i++) d[i] += d[i - 1]; for (int i = 1; i <= n; i++) { if (d[i] < a[i]) returnfalse; } returntrue; }
intmain(){ scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%lld", a + i); } for (int i = 1; i <= m; i++) { scanf("%d", b + i); } longlong l = 0, r = 2000000000, mid; while (l < r) { mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } printf("%lld\n", l); return0; }
int n, m; longlong a[maxn], d[maxn]; bool book[maxn];
boolcheck(longlong x){ longlong sum = 0, cnt1 = 0, cnt2 = 0; for (int i = 1; i <= n; i++) { if (book[i]) sum += max(0LL, x - (i - 1)); if (book[i] && i <= x) cnt2++; } if (sum < a[1]) returnfalse; for (int i = 2; i <= n; i++) { if (i + x - 1 <= n && book[i + x - 1]) cnt2++; if (book[i - 1]) cnt2--, cnt1++; sum += cnt2; sum -= cnt1; // if (x == 5) printf("%lld\n", sum); if (sum < a[i]) returnfalse; if (i - x >= 1 && book[i - x]) cnt1--; } returntrue; }
intmain(){ scanf("%d %d", &n, &m); bool flag = true; for (int i = 1; i <= n; i++) { scanf("%lld", a + i); if (a[i] != 0) flag = false; } if (flag) { printf("0\n"); return0; } for (int i = 1; i <= m; i++) { int x; scanf("%d", &x); book[x] = true; } longlong l = 1, r = 2000000000, mid; while (l < r) { mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } printf("%lld\n", l); return0; }