#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long oo = 1e18;
const long long N = 2e5 + 5;
ll n, m, h[N], dp[N];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
// #endif
cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> h[i];
for (int i = 0; i <= n + 1; i ++)
dp[i] = oo;
dp[0] = 0;
for (int i = 0; i <= n; i ++){
for (int j = i + 1; j <= n + 1; j ++)
if (h[j] <= h[i])
dp[j] = min(dp[j], dp[i] + j - i - 1);
else
if (h[i] + (j - i)*m >= h[j])
dp[j] = min(dp[j], dp[i] + j - i - 1);
// cout << dp[i] << ' ';
}
cout << dp[n + 1];
return 0;
}
/** /\_/\
(= ._.)
/ >0 \>1
________________________
/ Brainstorming section /
/=======================/
---
===
with two fixed point i, j you are allowed to change every pole between i, j
-> could it be changed so that you can go from i->j
possible case:
+ a[j] <= a[i]
+ a[j] - a[i] / m <= j - i + 1
===
**/
// Before submit: spot the visible bug by reading the code.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
15 ms |
332 KB |
Output is correct |
21 |
Correct |
16 ms |
412 KB |
Output is correct |
22 |
Correct |
46 ms |
332 KB |
Output is correct |
23 |
Correct |
42 ms |
332 KB |
Output is correct |
24 |
Correct |
42 ms |
460 KB |
Output is correct |
25 |
Correct |
23 ms |
332 KB |
Output is correct |
26 |
Correct |
22 ms |
332 KB |
Output is correct |
27 |
Correct |
32 ms |
408 KB |
Output is correct |
28 |
Correct |
28 ms |
424 KB |
Output is correct |
29 |
Correct |
19 ms |
332 KB |
Output is correct |
30 |
Correct |
21 ms |
332 KB |
Output is correct |
31 |
Correct |
17 ms |
368 KB |
Output is correct |
32 |
Correct |
23 ms |
424 KB |
Output is correct |
33 |
Correct |
23 ms |
424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
15 ms |
332 KB |
Output is correct |
5 |
Correct |
16 ms |
412 KB |
Output is correct |
6 |
Correct |
46 ms |
332 KB |
Output is correct |
7 |
Correct |
42 ms |
332 KB |
Output is correct |
8 |
Correct |
42 ms |
460 KB |
Output is correct |
9 |
Correct |
23 ms |
332 KB |
Output is correct |
10 |
Correct |
22 ms |
332 KB |
Output is correct |
11 |
Correct |
32 ms |
408 KB |
Output is correct |
12 |
Correct |
28 ms |
424 KB |
Output is correct |
13 |
Correct |
19 ms |
332 KB |
Output is correct |
14 |
Correct |
21 ms |
332 KB |
Output is correct |
15 |
Correct |
17 ms |
368 KB |
Output is correct |
16 |
Correct |
23 ms |
424 KB |
Output is correct |
17 |
Correct |
23 ms |
424 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
316 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
39 ms |
332 KB |
Output is correct |
35 |
Correct |
41 ms |
332 KB |
Output is correct |
36 |
Correct |
43 ms |
332 KB |
Output is correct |
37 |
Correct |
22 ms |
436 KB |
Output is correct |
38 |
Correct |
32 ms |
332 KB |
Output is correct |
39 |
Correct |
22 ms |
332 KB |
Output is correct |
40 |
Correct |
17 ms |
332 KB |
Output is correct |
41 |
Correct |
23 ms |
332 KB |
Output is correct |
42 |
Correct |
23 ms |
332 KB |
Output is correct |
43 |
Correct |
23 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
332 KB |
Output is correct |
2 |
Correct |
41 ms |
332 KB |
Output is correct |
3 |
Correct |
43 ms |
332 KB |
Output is correct |
4 |
Correct |
22 ms |
436 KB |
Output is correct |
5 |
Correct |
32 ms |
332 KB |
Output is correct |
6 |
Correct |
22 ms |
332 KB |
Output is correct |
7 |
Correct |
17 ms |
332 KB |
Output is correct |
8 |
Correct |
23 ms |
332 KB |
Output is correct |
9 |
Correct |
23 ms |
332 KB |
Output is correct |
10 |
Correct |
23 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
15 ms |
332 KB |
Output is correct |
15 |
Correct |
16 ms |
412 KB |
Output is correct |
16 |
Correct |
46 ms |
332 KB |
Output is correct |
17 |
Correct |
42 ms |
332 KB |
Output is correct |
18 |
Correct |
42 ms |
460 KB |
Output is correct |
19 |
Correct |
23 ms |
332 KB |
Output is correct |
20 |
Correct |
22 ms |
332 KB |
Output is correct |
21 |
Correct |
32 ms |
408 KB |
Output is correct |
22 |
Correct |
28 ms |
424 KB |
Output is correct |
23 |
Correct |
19 ms |
332 KB |
Output is correct |
24 |
Correct |
21 ms |
332 KB |
Output is correct |
25 |
Correct |
17 ms |
368 KB |
Output is correct |
26 |
Correct |
23 ms |
424 KB |
Output is correct |
27 |
Correct |
23 ms |
424 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
316 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Execution timed out |
1082 ms |
3820 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |