import
java.util.*;
public
class
Main {
static
class
IntPair {
int
first;
int
second;
IntPair(
int
x,
int
y)
{
this
.first = x;
this
.second = y;
}
}
static
class
HeapComparator
implements
Comparator<IntPair> {
public
int
compare(IntPair p1, IntPair p2)
{
if
(p1.first < p2.first)
return
1
;
else
if
(p1.first > p2.first)
return
-
1
;
return
0
;
}
}
static
int
maxScore(
int
A[],
int
K,
int
N)
{
PriorityQueue<IntPair> maxheap
=
new
PriorityQueue<IntPair>(
new
HeapComparator());
int
maxScore =
0
;
maxheap.add(
new
IntPair(A[
0
],
0
));
for
(
int
i =
1
; i < N; i++) {
while
(maxheap.peek().second < (i - K)) {
maxheap.remove();
}
maxScore = A[i] + maxheap.peek().first;
maxheap.add(
new
IntPair(maxScore, i));
}
return
maxScore;
}
public
static
void
main(String args[])
{
int
A[] = { -
44
, -
17
, -
54
,
79
};
int
K =
2
;
int
N = A.length;
System.out.println(maxScore(A, K, N));
}
}