int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i ) {
arr[i] = in.nextInt();
}
if (arr.length == 1){
System.out.println(arr[0]);
continue;
}
int k = in.nextInt();
int[] dp = new int[arr.length];
Deque<Integer> deque = new LinkedList<>();
for (int i = 0; i < arr.length; i ) {
if (!deque.isEmpty() && i - deque.peekFirst() > k) {
deque.pollFirst();
}
dp[i] = (deque.isEmpty() ? 0 : dp[deque.peekFirst()]) arr[i];
while (!deque.isEmpty() && dp[i] >= dp[deque.peekLast()]) {
deque.pollLast();
}
deque.offerLast(i);
}
System.out.println(dp[dp.length-1]);