Submission #521303

# Submission time Handle Problem Language Result Execution time Memory
521303 2022-02-01T14:56:16 Z sicho_mohit Rabbit Carrot (LMIO19_triusis) C++14
0 / 100
1 ms 332 KB
#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 time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Runtime error 1 ms 332 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Runtime error 1 ms 332 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Runtime error 1 ms 332 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Runtime error 1 ms 332 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -