This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// OwO mãi simp tnqa >~< UwU
//#pragma GCC target ("avx2")
//#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define f first
#define si second
#define ll long long
#define ul unsigned long long
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repp(i, a, b) for (int i = a; i >= b; --i)
#define TEST "TEST"
const ll maxn = 2e5 + 2;
//const ll oo = 1e18;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const ll mod[] = {(ll) 1e9 + 7, (ll)1e9 + 2277, (ll)1e9 + 5277, (ll)1e9 + 8277, (ll)1e9+ 9277};
const ll MOD = 1e9 + 7;
//const int LOG = 30;
const ll base = 71;
using namespace std;
inline int readInt(){char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong(){char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ul readUL(){char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}
int n, m, a[maxn], b[maxn], kq;
void sol(){
n = readInt(); m = readInt();
rep(i, 1, n){
a[i] = readInt();
}
rep(i, 1, n){
// if (i > 1 && a[i] < a[i - 1]){
// kq++; b[kq] = m * i - a[i];
// continue;
// }
if (m * i - a[i] < 0) continue;
if (kq == 0){
kq++; b[kq] = m * i - a[i];
}
else if (m * i - a[i] >= b[kq]){
kq++; b[kq] = m * i - a[i];
} else {
int k = upper_bound(b + 1, b + kq + 1, m * i - a[i]) - b;
b[k] = m * i - a[i];
}
}
cout << n - kq;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
if (fopen(TEST".INP","r")){
freopen(TEST".INP","r",stdin);
freopen(TEST".OUT","w",stdout);
}
int t; t = 1;
while (t--){
sol();
cout << "\n";
}
return 0;
}
Compilation message (stderr)
triusis.cpp: In function 'int main()':
triusis.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(TEST".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(TEST".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |