This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 2e6 + 5;
const int inf = 1e9;
int a[maxn],arr[maxn];
void input(int n){
arr[0] = inf;
for (int i = 1 ; i <= n ; i++){
cin >> a[i];
arr[i] = min(arr[i - 1],a[i] - i);
}
arr[0] = 0;
}
int freq[maxn];
int calc(const vector <int> &lst,int D){
int lim = 0;
for (int x : lst){
freq[x]++;
lim = max(lim,x);
}
int res = 0;
while (D && lim){
res += min(D,freq[lim]) * lim;
D -= min(D,freq[lim]);
lim--;
}
return res;
}
int solve(int n,int D,int T){
int cur = inf,res = 0;
vector <int> lst;
priority_queue <int> pq;
for (int i = n ; i > 0 ; i--){
int cur = a[i] - i,cnt = 0;
while (pq.size()){
int t = pq.top();
if (t >= cur){
cnt++;
pq.pop();
}
else break;
}
if (cnt > 0) lst.push_back(cnt);
if (i + arr[i] > T)
res++;
else if (a[i] > T)
pq.push(T - i);
}
return res + calc(lst,D);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,D,T;
cin >> n >> D >> T;
input(n);
cout << n - solve(n,D,T);
return 0;
}
Compilation message (stderr)
prison.cpp: In function 'int solve(int, int, int)':
prison.cpp:44:6: warning: unused variable 'cur' [-Wunused-variable]
44 | int cur = inf,res = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |