This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define all(a) a.begin(), a.end()
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
int n , m; cin >> n >> m;
vector<int>a(n);
for(int i = 0 ; i < n; i++)
cin >> a[i];
vector < int > ans;
for(int i = 0 ; i < n ; i++){
if(a[i] > (m * (i + 1))) continue;
a[i] = (m * (i + 1)) - a[i];
auto val = upper_bound(all(ans), a[i]);
if(val == ans.end()) ans.push_back(a[i]);
else *val = a[i];
}
cout << n - ans.size() << endl;
return 0 ;
}
/*
5 400
300 700 200 1000 500
lemma:
mmkn ageb el answer bta3t el range elle msh m7tag a8yr feh 7aga
b-keda a2dr ageb elle m7tag yt8yr
ummm el sample msln m7tag m8yrsh {300, 700, 200, 500}
keda 4th value heya elle htt8yr bs
hgeeb tle bardo keda O(n ^ 2), dp[idx][lst]
msln a7sn array ll-Rabbit heya {m, 2m, 3m, ...}
lw ana 3mlt el array blshkl da keda msln
umm ohhhh ana mmkn a3ml el shkl da en ashoof kol element m7tag 2d eh 3ashan ywsl ll-view da
[100, 100, 1000, 600, 1500]
a7sn range {100, 100, 1000, 15000}
gbt el 7l lol
*/
Compilation message (stderr)
triusis.cpp: In function 'int main()':
triusis.cpp:10:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
10 | for(int i = 0 ; i < n; i++)
| ^~~
triusis.cpp:12:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
12 | vector < int > ans;
| ^~~~~~| # | 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... |