Advertisement
999ms

Untitled

Aug 6th, 2020
2,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) begin(x),end(x)
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. const int N = 1e7 + 100;
  8.  
  9. bitset<N> bs;
  10.  
  11. int main() {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(nullptr);
  14.     cout.tie(nullptr); 
  15.     int b, n;
  16.     cin >> b >> n;
  17.     vector<int> a(b);
  18.     for (int i = 0; i < b; i++) cin >> a[i];
  19.     for (int i = 0; i < N; i++) bs[i] = 1;
  20.     bs[0] = 0;
  21.     for (int val : a) {
  22.         int pre = -10000;
  23.         for (int t = bs._Find_first(); ; t = bs._Find_next(t)) {
  24.             if (t - pre > n) {
  25.                 pre = t;
  26.                 bs[t] = 0;
  27.                 val--;
  28.                 if (val == 0) break;
  29.             }
  30.         }
  31.     }
  32.     int ans = 0;
  33.     for (int t = 1; t < N; t++) {
  34.         if (bs[t] == 0) ans = t;
  35.     }
  36.     cout << ans << '\n';
  37. }
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement