Submission #639612

#TimeUsernameProblemLanguageResultExecution timeMemory
639612luanaamorimK blocks (IZhO14_blocks)C++14
0 / 100
1 ms212 KiB
#include <iostream> #include <queue> #include <string> #include <algorithm> #include <vector> #include <cmath> #include <iomanip> #include <map> #include <cstring> #include <set> #include <stack> #include <bitset> #define MAX (int) 2e3 #define ll long long #define INF (ll)1e9 using namespace std; ll n, m, arr[MAX], dp[MAX][101], maior[MAX][MAX], memo[MAX][MAX], l, r, resp; ll f(int i, int k) { if (k < 0) return INF; if (i > n) return (k?INF:0); if (~memo[i][k]) return memo[i][k]; ll resp = INF; for (int j = i; j <= n; j++) resp = min(resp, f(j+1, k-1) + maior[i][j]); return memo[i][k] = resp; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> arr[i]; resp = max(resp, arr[i]); } m--; l = 1, r = n; while (m--) { if (arr[l] < arr[r]) { resp += arr[l]; l++; } else { resp += arr[r]; r--; } } cout << resp <<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...