Submission #1137849

#TimeUsernameProblemLanguageResultExecution timeMemory
1137849hoa208Rabbit Carrot (LMIO19_triusis)C++20
100 / 100
17 ms4936 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const ll mod = 1e9 + 7;
const ll INF = 1e17;
const ll N = 2e5 + 10;
ll n, m;
ll a[N];
namespace subX {
    ll b[N], c[N], d;
    void slove() {
        FOR(i, 1, n) {
            b[i] = 1LL * m * i - a[i];
        }
        FOR(i, 1, n) {
            if(b[i] < 0) continue;
            if(d == 0) {
                c[++d] = b[i];
                continue;
            }
            ll vt = upper_bound(c + 1, c + d + 1, b[i]) - c;
            c[vt] = b[i];
            d = max(vt, d);
        }
        cout << n - d;
    }
}

void hbmt() {
    // inp
    cin >> n >> m;
    FOR(i, 1, n) {
        cin >> a[i];
    }
    // slove
    return subX::slove();
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

Compilation message (stderr)

triusis.cpp: In function 'int main()':
triusis.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen("hbmt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...