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 int long long
using namespace std;
const int MAXN=2e6+5;
int n,d,T,a[MAXN];
int q[MAXN],tp;
bool fuc[MAXN];
int head[MAXN],tot;
struct node{int nxt,to;}e[MAXN<<1];
inline void add(int u,int v){
e[++tot].nxt=head[u];
e[tot].to=v;
head[u]=tot;
}
int dep[MAXN];
basic_string<int>cnt;
inline void dfs(int u){
int son=-1;
for(int i=head[u],v;i;i=e[i].nxt){
dfs(v=e[i].to);if(dep[u]<dep[v]){dep[u]=dep[v];son=v;}
}
dep[u]+=fuc[u];
for(int i=head[u],v;i;i=e[i].nxt){
if((v=e[i].to)!=son)cnt.push_back(-dep[v]);
}
}
signed main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>n>>d>>T;
for(int i=1;i<=n;i++)cin>>a[i];////
for(int i=n;i>=1;i--){
if(a[i]>T)q[++tp]=i;
else{
while(tp&&(a[i]+(q[tp]-i)<=T)){
fuc[q[tp]]=1;add(q[tp-1],q[tp]);tp--;
}
}
}
int ans=tp;
for(int i=1;i<=tp;i++)add(0,q[i]);
dfs(0);cnt.push_back(-dep[0]);
sort(cnt.begin(),cnt.end());
for(int i=0;i<cnt.size()&&i<d;i++)ans-=cnt[i];
cout<<n-ans<<"\n";
}
Compilation message (stderr)
prison.cpp: In function 'int main()':
prison.cpp:45:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0;i<cnt.size()&&i<d;i++)ans-=cnt[i];
| ~^~~~~~~~~~~
# | 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... |