Submission #99936

#TimeUsernameProblemLanguageResultExecution timeMemory
99936MohamedAhmed0K blocks (IZhO14_blocks)C++14
53 / 100
9 ms4864 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...