Pagini recente » Cod sursa (job #353782) | Cod sursa (job #927566) | Cod sursa (job #1605802) | Cod sursa (job #2467317) | Cod sursa (job #1130859)
type element=record
v,pos:longint;
end;
var n,i,j,t,k,min,x:longint;
deque:array[1..5000000]of element;
bufin:array[1..65000]of byte;
sum:int64;
begin
assign(input,'deque.in'); reset(input);
assign(output,'deque.out'); rewrite(output);
settextbuf(input,bufin);
readln(n,k);
i := 1; j := 0; sum := 0;
for t := 1 to n do
begin
readln(x);
if j >= i then
while deque[j].v > x do
begin
dec(j);
if j < i then break;
end;
inc(j); deque[j].v := x; deque[j].pos := t;
if deque[i].pos <= t - k then inc(i);
if t >= k then sum := sum + deque[i].v;
end;
writeln(sum);
close(input);
close(output);
end.