Submission #525286

# Submission time Handle Problem Language Result Execution time Memory
525286 2022-02-11T09:03:33 Z sicho_mohit Rabbit Carrot (LMIO19_triusis) C++14
100 / 100
86 ms 6328 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<int,int>>lis;
    for (int i=1;i<=n;i++)
    {
        if(is[i])
        {
            if(lis.size()==0)
            lis.pb({arr[i],i});
            else
            {
            pair<int,int>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 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 288 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 296 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 292 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 432 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 428 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 2 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 432 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 0 ms 292 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 288 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 296 KB Output is correct
34 Correct 3 ms 300 KB Output is correct
35 Correct 3 ms 308 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 356 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 304 KB Output is correct
42 Correct 2 ms 332 KB Output is correct
43 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 300 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 356 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 304 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 292 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 432 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 428 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 308 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 0 ms 292 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 288 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 296 KB Output is correct
44 Correct 33 ms 4568 KB Output is correct
45 Correct 73 ms 4088 KB Output is correct
46 Correct 86 ms 3936 KB Output is correct
47 Correct 79 ms 3932 KB Output is correct
48 Correct 53 ms 5088 KB Output is correct
49 Correct 68 ms 5328 KB Output is correct
50 Correct 85 ms 5072 KB Output is correct
51 Correct 78 ms 6328 KB Output is correct
52 Correct 49 ms 4060 KB Output is correct
53 Correct 54 ms 3284 KB Output is correct
54 Correct 57 ms 5212 KB Output is correct
55 Correct 52 ms 5276 KB Output is correct