Submission #666413

#TimeUsernameProblemLanguageResultExecution timeMemory
666413MilosMilutinovicThe short shank; Redemption (BOI21_prison)C++17
0 / 100
2083 ms4204 KiB
/**
 *    author:  wxhtzdy
 *    created: 28.11.2022 15:11:47
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, d, t;
  cin >> n >> d >> t;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> prv(n);
  vector<int> stk;
  for (int i = 0; i < n; i++) {
    prv[i] = -1;      
    for (int j = 0; j <= i; j++) {
      if (a[j] + (i - j) <= t) {
        prv[i] = j;        
      }
    }
    /* while (!stk.empty() && a[stk.back()] + i - stk.back() > t) {
      stk.pop_back();
    }
    while (!stk.empty() && a[stk.back()] - stk.back() > a[i] - i) {
      stk.pop_back();
    }      
    prv[i] = (a[i] <= t ? i : (stk.empty() ? -1 : stk.back()));
    stk.push_back(i); */
  }
  int ans = 0;
  vector<int> cnt(n);
  for (int i = 0; i < n; i++) {
    if (prv[i] != -1) {
      ans += 1;
      if (prv[i] != i) {
        cnt[prv[i]] += 1;
      }
    }  
  }
  set<pair<int, int>> st;
  for (int i = 0; i < n; i++) {
    st.emplace(cnt[i], i);
  }
  vector<bool> rem(n);
  for (int i = 0; i < d; i++) {
    auto it = prev(st.end());
    int idx = it->second;
    ans -= it->first;
    st.erase(it);   
    rem[idx] = true;
    for (int j = idx + 1; j < n; j++) {
      if (prv[j] != -1 && prv[j] < idx) {
        if (!rem[prv[j]]) {
          st.erase(make_pair(cnt[prv[j]], prv[j]));
          cnt[prv[j]] -= 1;
          st.emplace(cnt[prv[j]], prv[j]);
          prv[j] = -1;
        }              
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...