#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pi;
#define MOD 1000000007LL
ll N, M;
vector<ll> a;
int main() {
//freopen("feast.in", "r", stdin);
//freopen("feast.out", "w", stdout);
//ios_base::sync_with_stdio(false);
//cin.tie(0);
cin >> N >> M;
a.resize(N+1);
a[0] = 0;
for (int i = 1; i <= N; i++) cin >> a[i];
vector<ll> lis{ 0 };
vector<ll> slis{ 0 };
for (ll i = 1; i <= N; i++) {
if (a[i] <= (lis.back() + M*(i-slis.back())) + M) {
lis.push_back(a[i]);
slis.push_back(i+1);
} else if (a[i] > i*M) {
a[i] = a[i];
} else {
int lo = -1, hi = lis.size()-1;
while (lo < hi) {
int mid = (lo+hi+1)/2;
ll val = (lis[mid] + M*(i-slis[mid])) + M;
if (a[i] <= val) lo = mid;
else hi = mid-1;
}
lis[lo+1] = a[i];
slis[lo+1] = i+1;
}
//cout << "After round " << i << endl;
//for (auto x : lis) cout << x << " "; cout << endl;
//for (auto x : slis) cout << x << " "; cout << endl;
}
cout << N+1-lis.size() << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Incorrect |
3 ms |
492 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Incorrect |
3 ms |
492 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |