#include <bits/stdc++.h>
using namespace std;
const int maxn=1e4;
int v[maxn],dp[maxn][maxn];
int n,m;
int main(){
cin >> n>> m;
for(int i=0; i<n; i++)cin >> v[i+1];
for(int i=0; i<=n; i++)for(int j=0; j<=n; j++) dp[i][j]=-1;
for(int i=0; i<=n; i++) dp[0][i]=0;
for(int i=1; i<=n; i++) for(int j=0; j<=n; j++){
int npega=dp[i-1][j];
if(npega==-1) npega=-1;
else if(npega>=v[i])npega=v[i];
else if(npega+m<v[i])npega=-1;
else npega=v[i];
int pega;
if(j==0)pega=-1;
else{
pega=dp[i-1][j-1];
if(pega==-1) pega=-1;
else if(pega>=v[i]) pega=pega+m;
else pega=pega+m;
}
dp[i][j]=max(pega,npega);
}
for(int i=0; i<=n; i++){
if(dp[n][i]!=-1){
cout << i <<endl;
break;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
58 ms |
80844 KB |
Output is correct |
21 |
Correct |
81 ms |
118544 KB |
Output is correct |
22 |
Correct |
85 ms |
118548 KB |
Output is correct |
23 |
Correct |
88 ms |
118476 KB |
Output is correct |
24 |
Correct |
83 ms |
118604 KB |
Output is correct |
25 |
Correct |
92 ms |
118504 KB |
Output is correct |
26 |
Correct |
86 ms |
118524 KB |
Output is correct |
27 |
Correct |
100 ms |
118548 KB |
Output is correct |
28 |
Correct |
95 ms |
118552 KB |
Output is correct |
29 |
Correct |
87 ms |
118540 KB |
Output is correct |
30 |
Correct |
89 ms |
118544 KB |
Output is correct |
31 |
Correct |
84 ms |
118548 KB |
Output is correct |
32 |
Correct |
94 ms |
118532 KB |
Output is correct |
33 |
Correct |
103 ms |
118604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
58 ms |
80844 KB |
Output is correct |
5 |
Correct |
81 ms |
118544 KB |
Output is correct |
6 |
Correct |
85 ms |
118548 KB |
Output is correct |
7 |
Correct |
88 ms |
118476 KB |
Output is correct |
8 |
Correct |
83 ms |
118604 KB |
Output is correct |
9 |
Correct |
92 ms |
118504 KB |
Output is correct |
10 |
Correct |
86 ms |
118524 KB |
Output is correct |
11 |
Correct |
100 ms |
118548 KB |
Output is correct |
12 |
Correct |
95 ms |
118552 KB |
Output is correct |
13 |
Correct |
87 ms |
118540 KB |
Output is correct |
14 |
Correct |
89 ms |
118544 KB |
Output is correct |
15 |
Correct |
84 ms |
118548 KB |
Output is correct |
16 |
Correct |
94 ms |
118532 KB |
Output is correct |
17 |
Correct |
103 ms |
118604 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
90 ms |
118584 KB |
Output is correct |
35 |
Correct |
89 ms |
118580 KB |
Output is correct |
36 |
Correct |
91 ms |
118476 KB |
Output is correct |
37 |
Correct |
97 ms |
118464 KB |
Output is correct |
38 |
Correct |
99 ms |
118460 KB |
Output is correct |
39 |
Correct |
96 ms |
118604 KB |
Output is correct |
40 |
Correct |
88 ms |
118536 KB |
Output is correct |
41 |
Correct |
87 ms |
118488 KB |
Output is correct |
42 |
Correct |
94 ms |
118476 KB |
Output is correct |
43 |
Correct |
85 ms |
118476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
118584 KB |
Output is correct |
2 |
Correct |
89 ms |
118580 KB |
Output is correct |
3 |
Correct |
91 ms |
118476 KB |
Output is correct |
4 |
Correct |
97 ms |
118464 KB |
Output is correct |
5 |
Correct |
99 ms |
118460 KB |
Output is correct |
6 |
Correct |
96 ms |
118604 KB |
Output is correct |
7 |
Correct |
88 ms |
118536 KB |
Output is correct |
8 |
Correct |
87 ms |
118488 KB |
Output is correct |
9 |
Correct |
94 ms |
118476 KB |
Output is correct |
10 |
Correct |
85 ms |
118476 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
58 ms |
80844 KB |
Output is correct |
15 |
Correct |
81 ms |
118544 KB |
Output is correct |
16 |
Correct |
85 ms |
118548 KB |
Output is correct |
17 |
Correct |
88 ms |
118476 KB |
Output is correct |
18 |
Correct |
83 ms |
118604 KB |
Output is correct |
19 |
Correct |
92 ms |
118504 KB |
Output is correct |
20 |
Correct |
86 ms |
118524 KB |
Output is correct |
21 |
Correct |
100 ms |
118548 KB |
Output is correct |
22 |
Correct |
95 ms |
118552 KB |
Output is correct |
23 |
Correct |
87 ms |
118540 KB |
Output is correct |
24 |
Correct |
89 ms |
118544 KB |
Output is correct |
25 |
Correct |
84 ms |
118548 KB |
Output is correct |
26 |
Correct |
94 ms |
118532 KB |
Output is correct |
27 |
Correct |
103 ms |
118604 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Runtime error |
7 ms |
596 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |