#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[i] - i*m >= h[j] - j*m)
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]
+ h[i] + (j - i)*m >= h[j]
===
**/
// Before submit: spot the visible bug by reading the code.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
11 ms |
392 KB |
Output is correct |
21 |
Correct |
17 ms |
400 KB |
Output is correct |
22 |
Correct |
38 ms |
388 KB |
Output is correct |
23 |
Correct |
17 ms |
400 KB |
Output is correct |
24 |
Correct |
17 ms |
404 KB |
Output is correct |
25 |
Correct |
17 ms |
404 KB |
Output is correct |
26 |
Correct |
25 ms |
408 KB |
Output is correct |
27 |
Correct |
27 ms |
332 KB |
Output is correct |
28 |
Correct |
17 ms |
404 KB |
Output is correct |
29 |
Correct |
27 ms |
332 KB |
Output is correct |
30 |
Correct |
20 ms |
332 KB |
Output is correct |
31 |
Correct |
17 ms |
404 KB |
Output is correct |
32 |
Correct |
18 ms |
332 KB |
Output is correct |
33 |
Correct |
17 ms |
404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
11 ms |
392 KB |
Output is correct |
5 |
Correct |
17 ms |
400 KB |
Output is correct |
6 |
Correct |
38 ms |
388 KB |
Output is correct |
7 |
Correct |
17 ms |
400 KB |
Output is correct |
8 |
Correct |
17 ms |
404 KB |
Output is correct |
9 |
Correct |
17 ms |
404 KB |
Output is correct |
10 |
Correct |
25 ms |
408 KB |
Output is correct |
11 |
Correct |
27 ms |
332 KB |
Output is correct |
12 |
Correct |
17 ms |
404 KB |
Output is correct |
13 |
Correct |
27 ms |
332 KB |
Output is correct |
14 |
Correct |
20 ms |
332 KB |
Output is correct |
15 |
Correct |
17 ms |
404 KB |
Output is correct |
16 |
Correct |
18 ms |
332 KB |
Output is correct |
17 |
Correct |
17 ms |
404 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
38 ms |
332 KB |
Output is correct |
35 |
Correct |
39 ms |
388 KB |
Output is correct |
36 |
Correct |
39 ms |
380 KB |
Output is correct |
37 |
Correct |
20 ms |
404 KB |
Output is correct |
38 |
Correct |
28 ms |
404 KB |
Output is correct |
39 |
Correct |
18 ms |
408 KB |
Output is correct |
40 |
Correct |
17 ms |
396 KB |
Output is correct |
41 |
Correct |
17 ms |
400 KB |
Output is correct |
42 |
Correct |
17 ms |
332 KB |
Output is correct |
43 |
Correct |
17 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
332 KB |
Output is correct |
2 |
Correct |
39 ms |
388 KB |
Output is correct |
3 |
Correct |
39 ms |
380 KB |
Output is correct |
4 |
Correct |
20 ms |
404 KB |
Output is correct |
5 |
Correct |
28 ms |
404 KB |
Output is correct |
6 |
Correct |
18 ms |
408 KB |
Output is correct |
7 |
Correct |
17 ms |
396 KB |
Output is correct |
8 |
Correct |
17 ms |
400 KB |
Output is correct |
9 |
Correct |
17 ms |
332 KB |
Output is correct |
10 |
Correct |
17 ms |
400 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
11 ms |
392 KB |
Output is correct |
15 |
Correct |
17 ms |
400 KB |
Output is correct |
16 |
Correct |
38 ms |
388 KB |
Output is correct |
17 |
Correct |
17 ms |
400 KB |
Output is correct |
18 |
Correct |
17 ms |
404 KB |
Output is correct |
19 |
Correct |
17 ms |
404 KB |
Output is correct |
20 |
Correct |
25 ms |
408 KB |
Output is correct |
21 |
Correct |
27 ms |
332 KB |
Output is correct |
22 |
Correct |
17 ms |
404 KB |
Output is correct |
23 |
Correct |
27 ms |
332 KB |
Output is correct |
24 |
Correct |
20 ms |
332 KB |
Output is correct |
25 |
Correct |
17 ms |
404 KB |
Output is correct |
26 |
Correct |
18 ms |
332 KB |
Output is correct |
27 |
Correct |
17 ms |
404 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Execution timed out |
1095 ms |
3404 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |