Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- const int N = 1e7 + 100;
- bitset<N> bs;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int b, n;
- cin >> b >> n;
- vector<int> a(b);
- for (int i = 0; i < b; i++) cin >> a[i];
- for (int i = 0; i < N; i++) bs[i] = 1;
- bs[0] = 0;
- for (int val : a) {
- int pre = -10000;
- for (int t = bs._Find_first(); ; t = bs._Find_next(t)) {
- if (t - pre > n) {
- pre = t;
- bs[t] = 0;
- val--;
- if (val == 0) break;
- }
- }
- }
- int ans = 0;
- for (int t = 1; t < N; t++) {
- if (bs[t] == 0) ans = t;
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement