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>
typedef std::pair<int,int> pii;
int main()
{
int N,T,K;
std::cin>>N>>K>>T;
int array[N];for(auto&x:array)std::cin>>x;
///Tarefa: Achar para cada cara o PRIMEIRO x valido
int dp[N]={};
///Quero minimizar o custo
std::deque<pii> stack;
for(int i=0;i!=N;++i){
int custo = array[i]-i;
while(stack.size()&&stack.front().first>=custo){
stack.pop_front();
}
stack.push_front({custo,i});
///O valor tem que ser menor ou igual ao desejo
int desejo = T-i;
int l=0,r=stack.size()-1;
while(l<r){
int m = (l+r)/2;
if(stack[m].first<=desejo){
r=m;
}else l=m+1;
}
if(array[i]>T)
if(stack[l].first<=desejo){
// printf("Liga %d %d\n",i,stack[l].second);
++dp[stack[l].second];
}
}
std::vector<int> vec;
for(int i=0;i!=N;++i)vec.push_back(dp[i]);
std::sort(vec.begin(),vec.end(),std::greater<int>());
int sum=0;
for(int i=0;i!=K;++i)sum+=vec[i];
std::cout<<(N-sum)<<"\n";
}
# | 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... |