# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1216615 | maomao | The short shank; Redemption (BOI21_prison) | C++20 | 0 ms | 0 KiB |
//https://oj.uz/problem/view/BOI21_prison
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
int main() {
int n,d,t; cin >> n >> d >> t;
int p[n+1]; int prev = n;
FOR(i,1,n+1) cin >> p[i];
priority_queue<pii,vector<pii>> pq;
//find pos to put mattress
for(int i=n;i>1;i--) {
if(p[i]>t && t>p[i-1]) {
pq.push({max(prev-i+1,t-p[i-1]),i-1});
prev=i-1;
}
}
//take D topmost
int pos[d];
for(int i=0;i<d;i++) {
pos[i] = pq.top().s;
pq.pop();
}
sort(pos,pos+d);
for(int i=0;i<d-1;i++) {
int l=pos[i]+1, r=pos[i+1]-1;
for(int j=l;j<r;j++){
if(p[j]<t && t<p[j+1]) p[j+1] = p[j]+1;
}
}
int ans = 0;
for(int i=1;i<=n;i++) if(p[i]<=t) ans++;
cout << ans;
return 0;
}