Submission #874304

#TimeUsernameProblemLanguageResultExecution timeMemory
874304mall0809Rabbit Carrot (LMIO19_triusis)C++17
100 / 100
27 ms5336 KiB
 #include <bits/stdc++.h>

#define C int(1e6+7)
#define el '\n'
#define MOD int(1e9+7)
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
typedef long long ll;

const ll M = 5e18;
ll dp[C];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("cowjog.in","r",stdin);
//    freopen("cowjog.out","w",stdout);

    int n,k;cin>>n>>k;
    vector<int> a;
    for(int i=1;i<=n;i++){
        ll x;cin>>x;
        x = (ll)k*i-x;
        if(x >= 0)a.pb(x);//if neg,must be change as in the first step from 0,you can't jump on it
    }


    for(int i=1;i<=a.size();i++)dp[i] = M;
    dp[0] = 0;
    for(int i=0;i<a.size();i++){
        int id = upper_bound(dp,dp+a.size()+1,a[i]) - dp;
        if(dp[id-1] <= a[i] && a[i] < dp[id])dp[id] = a[i];
    }
    for(int i=a.size();i>=0;i--){
        if(dp[i] != M){
            cout<<n-i;
            return 0;
        }
    }
}

Compilation message (stderr)

triusis.cpp: In function 'int main()':
triusis.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=1;i<=a.size();i++)dp[i] = M;
      |                 ~^~~~~~~~~~
triusis.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...