Submission #521303

#TimeUsernameProblemLanguageResultExecution timeMemory
521303sicho_mohitRabbit Carrot (LMIO19_triusis)C++14
0 / 100
1 ms332 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define ff first #define ss second using namespace std ; const int N=1e5; int main () { // find lis of all valid buildings and subtract it from the total buildings , // the left over buildings would be the buildings which would be changed // or we can say we have to minimse the buildings which needs to be changed , // so why not maximise the buildings that do not need to be changed and subtract them // from the total buildings ll n , m ; cin >> n >> m ; ll arr[n+1]; bool is[n+1]; memset(is,true,sizeof(is)); for (int i=1;i<=n;i++) { cin >> arr[i]; if(arr[i]>i*m) is[i]=false; } arr[0]=0; vector<pair<ll,ll>>lis; for (ll i=1;i<=n;i++) { if(is[i]) { if(lis.size()==0) lis.pb({arr[i],i}); else { pair<ll,ll>temp=lis.back(); if(arr[i]-temp.ff<=(i-temp.ss)*m) { lis.pb({arr[i],i}); } else { int l=0; int r=lis.size()-1; int ans=0; while(l<=r) { int mid=(l+r)/2; pair<int,int>temp=lis[mid]; if(arr[i]-temp.ff<=(i-temp.ss)*m) { ans=mid; l=mid+1; } else r=mid-1; } lis[ans+1]=make_pair(arr[i],i); } } } } cout<<n-lis.size()<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...