Submission #28387

#TimeUsernameProblemLanguageResultExecution timeMemory
28387laaS (#68)Wine Tasting (FXCUP2_wine)C++14
0 / 1
0 ms9052 KiB
#include<iostream> #include<algorithm> using namespace std; long long int d[2][300000]; long long int arr[300000]; int main() { int n, k; cin >> n >> k; bool ind = false; for (int i = 0; i < n; i++) { cin >> d[ind][i]; arr[i] = d[ind][i]; } long long int temp = 0; for (int i = 1; i < k; i++) { ind = !ind; for (int j = i; j < n; j++) { d[ind][j] = 0; for (int k = i - 1; k < j; k++) { temp = d[!ind][k]; if (arr[k] < arr[j]) temp += arr[j] - arr[k]; d[ind][j] = max(d[ind][j], temp); } } } temp = d[ind][k - 1]; for (int i = k; i < n; i++) temp = max(temp, d[ind][i]); cout << temp; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...