#include<bits/stdc++.h>
//#define int ll
#define forn(i,n) for(int i=0;i<(n);i++)
#define Forn(i,n) for(int i=1;i<=(n);i++)
#define ll long long
#define pb push_back
#define F first
#define S second
#define vi vector<long long>
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
#define st0(p) memset((p),0,sizeof(p))
#define sz(x) (x).size()
#define rz resize
using namespace std;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cerr << a << " "; debug(b...);}
const int N = (int) 2e6+9;
const int INF = (int) 1e9 + 7;
int n,k;
struct FenwickTree{
int t[N];
void init(){
for(auto &i : t) i = -INF;
}
void modify(int p,int v){
for(;p <= n+1;p++){
t[p] = max(t[p],v);
}
}
int query(int p){
int res = -INF;
for(;p;p-=(p&-p)) res = max(res,t[p]);
return res;
}
}bit;
void solve(){
cin >> n >> k;
vi a(n);
forn(i,n) cin >> a[i];
for(int i = 1;i <= n;i++){
a[i-1] -= k * i;
a[i-1] *= -1;
}
vi dp(n);
vi rk = a;
rk.pb(0);
sort(all(rk));
rk.resize(unique(all(rk)) - rk.begin());
forn(i,n){
a[i] = upper_bound(all(rk),a[i]) - rk.begin();
}
bit.init();
bit.modify(upper_bound(all(rk),0)-rk.begin(),0);
forn(i,n){
dp[i] = bit.query(a[i]) + 1;
bit.modify(a[i],dp[i]);
}
cout << n - bit.query(n+1) << '\n';
}
signed main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
4 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8020 KB |
Output is correct |
7 |
Correct |
5 ms |
8020 KB |
Output is correct |
8 |
Correct |
4 ms |
8020 KB |
Output is correct |
9 |
Correct |
4 ms |
8104 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
4 ms |
8020 KB |
Output is correct |
12 |
Correct |
4 ms |
8020 KB |
Output is correct |
13 |
Correct |
4 ms |
8020 KB |
Output is correct |
14 |
Correct |
4 ms |
8020 KB |
Output is correct |
15 |
Correct |
4 ms |
8020 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
4 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
4 ms |
8020 KB |
Output is correct |
7 |
Correct |
5 ms |
8020 KB |
Output is correct |
8 |
Correct |
4 ms |
8020 KB |
Output is correct |
9 |
Correct |
4 ms |
8104 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
4 ms |
8020 KB |
Output is correct |
12 |
Correct |
4 ms |
8020 KB |
Output is correct |
13 |
Correct |
4 ms |
8020 KB |
Output is correct |
14 |
Correct |
4 ms |
8020 KB |
Output is correct |
15 |
Correct |
4 ms |
8020 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
4 ms |
8020 KB |
Output is correct |
18 |
Correct |
4 ms |
8020 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
11 ms |
8276 KB |
Output is correct |
21 |
Correct |
15 ms |
8276 KB |
Output is correct |
22 |
Correct |
18 ms |
8276 KB |
Output is correct |
23 |
Correct |
16 ms |
8280 KB |
Output is correct |
24 |
Correct |
14 ms |
8276 KB |
Output is correct |
25 |
Correct |
15 ms |
8304 KB |
Output is correct |
26 |
Correct |
15 ms |
8276 KB |
Output is correct |
27 |
Correct |
24 ms |
8276 KB |
Output is correct |
28 |
Correct |
24 ms |
8276 KB |
Output is correct |
29 |
Correct |
15 ms |
8276 KB |
Output is correct |
30 |
Correct |
15 ms |
8276 KB |
Output is correct |
31 |
Correct |
26 ms |
8276 KB |
Output is correct |
32 |
Correct |
15 ms |
8200 KB |
Output is correct |
33 |
Correct |
15 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
11 ms |
8276 KB |
Output is correct |
5 |
Correct |
15 ms |
8276 KB |
Output is correct |
6 |
Correct |
18 ms |
8276 KB |
Output is correct |
7 |
Correct |
16 ms |
8280 KB |
Output is correct |
8 |
Correct |
14 ms |
8276 KB |
Output is correct |
9 |
Correct |
15 ms |
8304 KB |
Output is correct |
10 |
Correct |
15 ms |
8276 KB |
Output is correct |
11 |
Correct |
24 ms |
8276 KB |
Output is correct |
12 |
Correct |
24 ms |
8276 KB |
Output is correct |
13 |
Correct |
15 ms |
8276 KB |
Output is correct |
14 |
Correct |
15 ms |
8276 KB |
Output is correct |
15 |
Correct |
26 ms |
8276 KB |
Output is correct |
16 |
Correct |
15 ms |
8200 KB |
Output is correct |
17 |
Correct |
15 ms |
8276 KB |
Output is correct |
18 |
Correct |
4 ms |
8020 KB |
Output is correct |
19 |
Correct |
4 ms |
8020 KB |
Output is correct |
20 |
Correct |
4 ms |
8020 KB |
Output is correct |
21 |
Correct |
4 ms |
8020 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8020 KB |
Output is correct |
24 |
Correct |
5 ms |
8020 KB |
Output is correct |
25 |
Correct |
4 ms |
8020 KB |
Output is correct |
26 |
Correct |
4 ms |
8104 KB |
Output is correct |
27 |
Correct |
4 ms |
8020 KB |
Output is correct |
28 |
Correct |
4 ms |
8020 KB |
Output is correct |
29 |
Correct |
4 ms |
8020 KB |
Output is correct |
30 |
Correct |
4 ms |
8020 KB |
Output is correct |
31 |
Correct |
4 ms |
8020 KB |
Output is correct |
32 |
Correct |
4 ms |
8020 KB |
Output is correct |
33 |
Correct |
4 ms |
8148 KB |
Output is correct |
34 |
Correct |
15 ms |
8272 KB |
Output is correct |
35 |
Correct |
15 ms |
8276 KB |
Output is correct |
36 |
Correct |
17 ms |
8276 KB |
Output is correct |
37 |
Correct |
14 ms |
8276 KB |
Output is correct |
38 |
Correct |
26 ms |
8312 KB |
Output is correct |
39 |
Correct |
32 ms |
8276 KB |
Output is correct |
40 |
Correct |
22 ms |
8296 KB |
Output is correct |
41 |
Correct |
25 ms |
8308 KB |
Output is correct |
42 |
Correct |
15 ms |
8276 KB |
Output is correct |
43 |
Correct |
15 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8272 KB |
Output is correct |
2 |
Correct |
15 ms |
8276 KB |
Output is correct |
3 |
Correct |
17 ms |
8276 KB |
Output is correct |
4 |
Correct |
14 ms |
8276 KB |
Output is correct |
5 |
Correct |
26 ms |
8312 KB |
Output is correct |
6 |
Correct |
32 ms |
8276 KB |
Output is correct |
7 |
Correct |
22 ms |
8296 KB |
Output is correct |
8 |
Correct |
25 ms |
8308 KB |
Output is correct |
9 |
Correct |
15 ms |
8276 KB |
Output is correct |
10 |
Correct |
15 ms |
8276 KB |
Output is correct |
11 |
Correct |
4 ms |
8020 KB |
Output is correct |
12 |
Correct |
4 ms |
8020 KB |
Output is correct |
13 |
Correct |
4 ms |
8148 KB |
Output is correct |
14 |
Correct |
11 ms |
8276 KB |
Output is correct |
15 |
Correct |
15 ms |
8276 KB |
Output is correct |
16 |
Correct |
18 ms |
8276 KB |
Output is correct |
17 |
Correct |
16 ms |
8280 KB |
Output is correct |
18 |
Correct |
14 ms |
8276 KB |
Output is correct |
19 |
Correct |
15 ms |
8304 KB |
Output is correct |
20 |
Correct |
15 ms |
8276 KB |
Output is correct |
21 |
Correct |
24 ms |
8276 KB |
Output is correct |
22 |
Correct |
24 ms |
8276 KB |
Output is correct |
23 |
Correct |
15 ms |
8276 KB |
Output is correct |
24 |
Correct |
15 ms |
8276 KB |
Output is correct |
25 |
Correct |
26 ms |
8276 KB |
Output is correct |
26 |
Correct |
15 ms |
8200 KB |
Output is correct |
27 |
Correct |
15 ms |
8276 KB |
Output is correct |
28 |
Correct |
4 ms |
8020 KB |
Output is correct |
29 |
Correct |
4 ms |
8020 KB |
Output is correct |
30 |
Correct |
4 ms |
8020 KB |
Output is correct |
31 |
Correct |
4 ms |
8020 KB |
Output is correct |
32 |
Correct |
4 ms |
8148 KB |
Output is correct |
33 |
Correct |
4 ms |
8020 KB |
Output is correct |
34 |
Correct |
5 ms |
8020 KB |
Output is correct |
35 |
Correct |
4 ms |
8020 KB |
Output is correct |
36 |
Correct |
4 ms |
8104 KB |
Output is correct |
37 |
Correct |
4 ms |
8020 KB |
Output is correct |
38 |
Correct |
4 ms |
8020 KB |
Output is correct |
39 |
Correct |
4 ms |
8020 KB |
Output is correct |
40 |
Correct |
4 ms |
8020 KB |
Output is correct |
41 |
Correct |
4 ms |
8020 KB |
Output is correct |
42 |
Correct |
4 ms |
8020 KB |
Output is correct |
43 |
Correct |
4 ms |
8148 KB |
Output is correct |
44 |
Execution timed out |
1087 ms |
12720 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |