#include <bits/stdc++.h>
using namespace std;
int dp[105][105][105] ;
int arr[105] ;
int n , k ;
int solve(int idx , int idx2 , int cnt)
{
if(cnt > k)
return 1e9 ;
if(idx == n)
{
if(cnt != k)
return 1e9 ;
return arr[idx2] ;
}
int &ret = dp[idx][idx2][cnt] ;
if(ret != -1)
return ret ;
if(idx == 0)
{
ret = solve(idx+1 , 0 , 1) ;
return ret ;
}
ret = solve(idx+1 , idx , cnt+1) + arr[idx2] ;
if(arr[idx] > arr[idx2])
idx2 = idx ;
ret = min(ret , solve(idx+1 , idx2 , cnt));
return ret ;
}
int main()
{
memset(dp , -1 , sizeof(dp));
scanf("%d %d" , &n , &k) ;
for(int i = 0 ; i < n ; ++i)
cin>>arr[i] ;
return cout<<solve(0 , 0 , 0)<<"\n" , 0 ;
}
Compilation message
blocks.cpp: In function 'int main()':
blocks.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d" , &n , &k) ;
~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4864 KB |
Output is correct |
2 |
Correct |
6 ms |
4864 KB |
Output is correct |
3 |
Correct |
5 ms |
4864 KB |
Output is correct |
4 |
Correct |
6 ms |
4864 KB |
Output is correct |
5 |
Correct |
6 ms |
4864 KB |
Output is correct |
6 |
Correct |
6 ms |
4864 KB |
Output is correct |
7 |
Correct |
6 ms |
4864 KB |
Output is correct |
8 |
Correct |
6 ms |
4864 KB |
Output is correct |
9 |
Correct |
6 ms |
4812 KB |
Output is correct |
10 |
Correct |
7 ms |
4864 KB |
Output is correct |
11 |
Correct |
7 ms |
4864 KB |
Output is correct |
12 |
Correct |
7 ms |
4864 KB |
Output is correct |
13 |
Correct |
6 ms |
4864 KB |
Output is correct |
14 |
Correct |
6 ms |
4836 KB |
Output is correct |
15 |
Correct |
7 ms |
4864 KB |
Output is correct |
16 |
Correct |
7 ms |
4864 KB |
Output is correct |
17 |
Correct |
7 ms |
4864 KB |
Output is correct |
18 |
Correct |
6 ms |
4836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4864 KB |
Output is correct |
2 |
Correct |
6 ms |
4864 KB |
Output is correct |
3 |
Correct |
6 ms |
4864 KB |
Output is correct |
4 |
Correct |
6 ms |
4864 KB |
Output is correct |
5 |
Correct |
6 ms |
4864 KB |
Output is correct |
6 |
Correct |
6 ms |
4864 KB |
Output is correct |
7 |
Correct |
6 ms |
4864 KB |
Output is correct |
8 |
Correct |
6 ms |
4864 KB |
Output is correct |
9 |
Correct |
6 ms |
4864 KB |
Output is correct |
10 |
Correct |
6 ms |
4864 KB |
Output is correct |
11 |
Correct |
6 ms |
4864 KB |
Output is correct |
12 |
Correct |
5 ms |
4864 KB |
Output is correct |
13 |
Correct |
6 ms |
4864 KB |
Output is correct |
14 |
Correct |
5 ms |
4864 KB |
Output is correct |
15 |
Correct |
6 ms |
4864 KB |
Output is correct |
16 |
Correct |
6 ms |
4864 KB |
Output is correct |
17 |
Correct |
5 ms |
4864 KB |
Output is correct |
18 |
Correct |
6 ms |
4864 KB |
Output is correct |
19 |
Correct |
6 ms |
4864 KB |
Output is correct |
20 |
Correct |
6 ms |
4780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4864 KB |
Output is correct |
2 |
Correct |
5 ms |
4864 KB |
Output is correct |
3 |
Correct |
6 ms |
4864 KB |
Output is correct |
4 |
Correct |
5 ms |
4864 KB |
Output is correct |
5 |
Correct |
6 ms |
4864 KB |
Output is correct |
6 |
Correct |
6 ms |
4864 KB |
Output is correct |
7 |
Correct |
6 ms |
4864 KB |
Output is correct |
8 |
Correct |
7 ms |
4864 KB |
Output is correct |
9 |
Correct |
6 ms |
4864 KB |
Output is correct |
10 |
Correct |
7 ms |
4864 KB |
Output is correct |
11 |
Correct |
6 ms |
4864 KB |
Output is correct |
12 |
Correct |
6 ms |
4864 KB |
Output is correct |
13 |
Correct |
7 ms |
4864 KB |
Output is correct |
14 |
Correct |
6 ms |
4864 KB |
Output is correct |
15 |
Correct |
7 ms |
4864 KB |
Output is correct |
16 |
Correct |
6 ms |
4864 KB |
Output is correct |
17 |
Correct |
6 ms |
4864 KB |
Output is correct |
18 |
Correct |
6 ms |
4864 KB |
Output is correct |
19 |
Correct |
8 ms |
4864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |