#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 998244353
#define INF 900000000000000000
//#define cin fin
//#define cout fout
#define fi first
#define se second
using namespace std;
//ofstream fout("intel.out");
//ifstream fin("intel.in");
const int Max = 5e3 + 1;
long long dp[Max][Max];
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n, m; cin >> n >> m; long long arr[n+1];
for(int i = 1; i <= n; i++) {
cin >> arr[i];
}
for(int i = 0; i < Max; i++) {
for(int j = 0; j < Max; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < Max; j++) {
if(j == arr[i]) {
dp[i][j] = min(dp[i-1][max(0,j-m)],dp[i][j]);
}
else {
dp[i][j] = min(dp[i-1][max(0,j-m)]+1,dp[i][j]);
}
}
for(int j = Max-2; j >= 0; j--) {
dp[i][j] = min(dp[i][j+1],dp[i][j]);
}
}
long long ans = INF;
for(int i = 0; i < Max; i++) {
ans = min(ans,dp[n][i]);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
196080 KB |
Output is correct |
2 |
Correct |
28 ms |
196112 KB |
Output is correct |
3 |
Correct |
27 ms |
196180 KB |
Output is correct |
4 |
Correct |
27 ms |
196180 KB |
Output is correct |
5 |
Correct |
26 ms |
196188 KB |
Output is correct |
6 |
Correct |
33 ms |
196052 KB |
Output is correct |
7 |
Correct |
27 ms |
196184 KB |
Output is correct |
8 |
Correct |
27 ms |
196004 KB |
Output is correct |
9 |
Correct |
27 ms |
196176 KB |
Output is correct |
10 |
Correct |
30 ms |
196184 KB |
Output is correct |
11 |
Correct |
32 ms |
196180 KB |
Output is correct |
12 |
Correct |
27 ms |
196188 KB |
Output is correct |
13 |
Correct |
28 ms |
195972 KB |
Output is correct |
14 |
Correct |
29 ms |
196180 KB |
Output is correct |
15 |
Correct |
27 ms |
196180 KB |
Output is correct |
16 |
Correct |
28 ms |
196180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
196080 KB |
Output is correct |
2 |
Correct |
28 ms |
196112 KB |
Output is correct |
3 |
Correct |
27 ms |
196180 KB |
Output is correct |
4 |
Correct |
27 ms |
196180 KB |
Output is correct |
5 |
Correct |
26 ms |
196188 KB |
Output is correct |
6 |
Correct |
33 ms |
196052 KB |
Output is correct |
7 |
Correct |
27 ms |
196184 KB |
Output is correct |
8 |
Correct |
27 ms |
196004 KB |
Output is correct |
9 |
Correct |
27 ms |
196176 KB |
Output is correct |
10 |
Correct |
30 ms |
196184 KB |
Output is correct |
11 |
Correct |
32 ms |
196180 KB |
Output is correct |
12 |
Correct |
27 ms |
196188 KB |
Output is correct |
13 |
Correct |
28 ms |
195972 KB |
Output is correct |
14 |
Correct |
29 ms |
196180 KB |
Output is correct |
15 |
Correct |
27 ms |
196180 KB |
Output is correct |
16 |
Correct |
28 ms |
196180 KB |
Output is correct |
17 |
Correct |
27 ms |
196180 KB |
Output is correct |
18 |
Correct |
30 ms |
196180 KB |
Output is correct |
19 |
Correct |
33 ms |
195988 KB |
Output is correct |
20 |
Correct |
77 ms |
196176 KB |
Output is correct |
21 |
Correct |
87 ms |
196184 KB |
Output is correct |
22 |
Correct |
87 ms |
196176 KB |
Output is correct |
23 |
Correct |
93 ms |
196268 KB |
Output is correct |
24 |
Correct |
100 ms |
196188 KB |
Output is correct |
25 |
Correct |
86 ms |
196184 KB |
Output is correct |
26 |
Correct |
86 ms |
196268 KB |
Output is correct |
27 |
Correct |
91 ms |
196060 KB |
Output is correct |
28 |
Correct |
85 ms |
196264 KB |
Output is correct |
29 |
Correct |
86 ms |
196188 KB |
Output is correct |
30 |
Correct |
84 ms |
196276 KB |
Output is correct |
31 |
Correct |
85 ms |
196096 KB |
Output is correct |
32 |
Correct |
91 ms |
196176 KB |
Output is correct |
33 |
Correct |
84 ms |
196176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
196180 KB |
Output is correct |
2 |
Correct |
30 ms |
196180 KB |
Output is correct |
3 |
Correct |
33 ms |
195988 KB |
Output is correct |
4 |
Correct |
77 ms |
196176 KB |
Output is correct |
5 |
Correct |
87 ms |
196184 KB |
Output is correct |
6 |
Correct |
87 ms |
196176 KB |
Output is correct |
7 |
Correct |
93 ms |
196268 KB |
Output is correct |
8 |
Correct |
100 ms |
196188 KB |
Output is correct |
9 |
Correct |
86 ms |
196184 KB |
Output is correct |
10 |
Correct |
86 ms |
196268 KB |
Output is correct |
11 |
Correct |
91 ms |
196060 KB |
Output is correct |
12 |
Correct |
85 ms |
196264 KB |
Output is correct |
13 |
Correct |
86 ms |
196188 KB |
Output is correct |
14 |
Correct |
84 ms |
196276 KB |
Output is correct |
15 |
Correct |
85 ms |
196096 KB |
Output is correct |
16 |
Correct |
91 ms |
196176 KB |
Output is correct |
17 |
Correct |
84 ms |
196176 KB |
Output is correct |
18 |
Correct |
28 ms |
196080 KB |
Output is correct |
19 |
Correct |
28 ms |
196112 KB |
Output is correct |
20 |
Correct |
27 ms |
196180 KB |
Output is correct |
21 |
Correct |
27 ms |
196180 KB |
Output is correct |
22 |
Correct |
26 ms |
196188 KB |
Output is correct |
23 |
Correct |
33 ms |
196052 KB |
Output is correct |
24 |
Correct |
27 ms |
196184 KB |
Output is correct |
25 |
Correct |
27 ms |
196004 KB |
Output is correct |
26 |
Correct |
27 ms |
196176 KB |
Output is correct |
27 |
Correct |
30 ms |
196184 KB |
Output is correct |
28 |
Correct |
32 ms |
196180 KB |
Output is correct |
29 |
Correct |
27 ms |
196188 KB |
Output is correct |
30 |
Correct |
28 ms |
195972 KB |
Output is correct |
31 |
Correct |
29 ms |
196180 KB |
Output is correct |
32 |
Correct |
27 ms |
196180 KB |
Output is correct |
33 |
Correct |
28 ms |
196180 KB |
Output is correct |
34 |
Correct |
88 ms |
196188 KB |
Output is correct |
35 |
Incorrect |
86 ms |
196300 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
196188 KB |
Output is correct |
2 |
Incorrect |
86 ms |
196300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |