import sequtils,math,times,deques template times*(n:int,body) = (for _ in 0..= y: x else: y) type SegmentTree[T] = object data:seq[T] # import math n : int rawSize:int infinity: T cmp:proc(x,y:T):T proc initSegmentTree[T]( size:int, infinity:T = T(1e10), cmp: proc (x,y:T):T = minimpl[T]) : SegmentTree[T] = result.infinity = infinity result.cmp = cmp result.n = size.nextPowerOfTwo() result.rawSize = size result.data = newSeqWith(result.n * 2,result.infinity) proc `[]=`[T](self:var SegmentTree[T],i:int,val:T) = var i = i + self.n - 1 self.data[i] = val while i > 0: i = (i - 1) shr 1 self.data[i] = self.cmp(self.data[i * 2 + 1],self.data[i * 2 + 2]) proc `[]`[T](self:SegmentTree[T],slice:Slice[int]): T = proc impl(a,b,k,l,r:int):T = if r <= a or b <= l : return self.infinity if a <= l and r <= b : return self.data[k] let vl = impl(a,b,k*2+1,l,(l+r) shr 1) let vr = impl(a,b,k*2+2,(l+r) shr 1,r) return self.cmp(vl,vr) return impl(slice.a,slice.b+1,0,0,self.n) proc `$`[T](self:SegmentTree[T]): string = var arrs : seq[seq[int]] = @[] var l = 0 var r = 1 while r <= self.data.len: arrs &= self.data[l..= y: x else: y) type SlideMin[T] = ref object deq:seq[int] vals:seq[T] l,r:int width:int len:int infinity: T cmp:proc(x,y:T):T proc initSlideMin[T]( width:int, cmp: proc (x,y:T):T = minimpl[T]) : SlideMin[T] = new(result) result.deq = newSeq[int]() result.vals = newSeq[T]() result.width = width + 1 result.cmp = cmp proc `&=`[T](self:SlideMin,val:T): T = # (自分を含む)過去width個での最小値を返す self.vals &= val while self.l < self.r and val == self.cmp(val,self.vals[self.deq[self.r-1]]): self.r -= 1 if self.deq.len > self.r : self.deq[self.r] = self.len else: self.deq &= self.len self.r += 1 self.len += 1 if self.len - self.width >= 0 : if self.deq[self.l] == self.len - self.width: self.l += 1 return self.vals[self.deq[self.l]] useSlideMin() proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord let n = scan() let d = scan() let k = scan() let S = newSeqWith(n,scan()) var slide = initSlideMin[int](d,maximpl) var ans = 0 var time = 0 var maxVal = 0 for i in 0..