You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
402 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int a[N];
int main() {
int n, k, ans = 0;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < n - k; i++)
ans = max(ans, a[i] + a[2 * (n - k) - i - 1]);
for (int i = 0; i < n; i++)
ans = max(ans, a[i]);
printf("%d", ans);
return 0;
}