Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

海岸線

海岸には毎秒波が押し寄せる．基準点 P を超えて何 m の地点まで波が押し寄せたかを，T 秒の間だけ毎秒観測し記録したデータがある．データは T 個の整数 x1, ..., xT からなり，各 i  (1 ≤ i ≤ T) に対し，観測を始めてから i 秒後には地点 P からちょうど xi m の地点までの波が押し寄せ，海水に浸っていたことを表す．

海岸は，最後に海水に浸ってから D 秒後に乾くことが分かっている．ここで，乾くまでの時間は最後に海水に浸った時間のみに依存し，それ以前に波に浸っていた回数や時間には依存しないことに注意せよ．

基準点 P から，陸の方向に距離 L だけ離れた地点が，観測を開始してから 1 秒後と T 秒後の間に少なくとも何秒間濡れていたかを求めよ．ただし，時刻 0 で海岸は乾いていたことがわかっている．

以下に，Sample Input 第1ケースの図を示す．

図B1: Sample Input 第1ケースの場合

Input

入力データセットは複数のケースから構成される．データセットの個数は最大でも 40 個を超えない．各ケースは次のような形式である．

T D L
x1
...
xT

1 行目には T, D, L  (1 ≤ T, D, L ≤ 100,000) が半角スペース区切りで与えられる．続く T 行のうち i  (1 ≤ i ≤ T) 行目には xi  (0 ≤ xi ≤ 100,000) が与えられる．これらは全て整数である．

データセットの終わりは，3 つの 0 からなる行で表される．

Output

各ケースに対し，基準点 P から，陸の方向に距離 L だけ離れた地点が 1 秒後から T 秒後の間で確実に濡れていた時間 (秒) を 1 行で出力せよ．

Sample Input

5 2 3
3
5
1
2
3
3 100 100
3
3
4
20 3 8
3
2
6
1
9
1
8
4
2
2
8
1
8
8
2
5
3
4
3
8
7 2 2
0
2
5
2
5
2
1
0 0 0

Output for Sample Input

3
0
11
5



Sample input:
5 2 3
3
5
1
2
3
3 100 100
3
3
4
20 3 8
3
2
6
1
9
1
8
4
2
2
8
1
8
8
2
5
3
4
3
8
7 2 2
0
2
5
2
5
2
1
0 0 0


Sample output:
3
0
11
5

Submission status: Accepted

Solution code:
# AOJ 2824: Coastline
# Python3 2018.7.11 bal4u

while True:
	T, D, L = map(int, input().split())
	if T == 0: break
	a = []
	for i in range(T):
		x = int(input())
		if x >= L: a.append(i)
	T, ans = T-1, 0
	for i in range(1, len(a)):
		x = D
		if T-a[i-1] < D: x = T-a[i-1]
		if a[i]-a[i-1] < x: ans += a[i]-a[i-1]
		else: ans += x
	if a: ans += T-a[-1] if a[-1]+D > T else D
	print(ans)

Submission status: Accepted

Solution code:
while 1:
    t,d,l=map(int,input().split())
    if not t+d+l:
        break
    a=0
    j=-1
    for i in range(t):
        x=int(input())
        a+=(j>-1and i-j<=d)
        if x>=l:
            j=i
    print(a)

Submission status: Accepted

Solution code:
while True:
    T, D, L = map(int, input().split())
    if T == 0:
        exit()
    ans = [0] * 200001
    for i in range(T):
        x = int(input())
        if i < T - 1 and x >= L:
            ans[i] += 1
            ans[i + D] -= 1

    for i in range(T):
        ans[i + 1] += ans[i]
    print(len([x for x in ans[:T - 1] if x > 0]))

Submission status: Accepted

Solution code:
while 1:
    T, D, L = map(int, input().split())
    # T秒間毎秒観測, T個の整数
    # 海岸はD秒後に乾く
    # 基準点から距離L離れたところが何秒間濡れていたか
    # i秒後にxiの地点まで波が押し寄せる
    if T == 0:
        exit()
    X = [int(input()) for _ in range(T)]
    wet_time = 0
    limit = 0
    ans = []

    for i in range(T):
        if limit > 0:
            limit -= 1
            wet_time += 1
        if X[i] >= L:
            limit = D  # 回復させる

        if limit == 0:
            ans.append(wet_time)
            wet_time = 0

    ans.append(wet_time)

    print(sum(ans))

Submission status: Accepted

Solution code:
while 1:

    T, D, L = map(int, input().split())
    # T秒間の間観測, 毎秒波が押し寄せてくる。T個のx
    # 海岸はD秒たつと乾く
    # 距離Lだけ離れた地点が少なくても何秒濡れていたか
    if T == 0:
        exit()
    XXX = [int(input()) for i in range(T)]

    limit_time = 0
    ans = 0
    swet_time = 0
    for i, x in enumerate(XXX):
        if limit_time > 0:
            swet_time += 1
            limit_time -= 1

        if x >= L:
            limit_time = D


        if limit_time == 0:
            ans += swet_time
            swet_time = 0
        elif i == len(XXX)-1:
            ans += swet_time

    print(ans)

Submission status: Accepted

Solution code:
while True:
    T,D,L=map(int,input().split())
    if T==0 and D==0 and L==0:
        break
    rem,ans=0,0
    for _ in [0]*T:
        x=int(input())
        if x >= L:
            rem=D
        if rem:
            ans+=1
            rem-=1
    if ans:
        ans-=1
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    t, d, l = map(int, raw_input().split())
    if t == d == l == 0:
        break
    rest = ans = 0
    for i in xrange(t):
        x = int(raw_input())
        if l <= x:
            rest = d
        elif rest:
            rest -= 1
        if rest and i < t-1:
            ans += 1
    print ans

Submission status: Accepted

Solution code:
while True:
    t, d, l = map(int, input().split())
    if t == 0:break
    a = [int(input()) for _ in range(t)]
    w = 0
    wd = 0
    for i in range(t):
        if a[i] >= l:
            if wd:
                w += 1
                wd = d
            else:
                wd = d
        else:
            if wd:
                w += 1
                wd -= 1
    print(w)

Submission status: Accepted

Solution code:
while True:
    try:
        T, D, L = map(int, input().split())
        if T == 0:
            break
        cnt = 0
        flag = 0
        delay = D
        for i in range(T):
            x = int(input())
            if x >= L:
                if flag == 1:
                    cnt += 1
                flag = 1
                delay = D
            else:
                if flag == 1:
                    delay -= 1
                    cnt += 1
                    if delay == 0:
                        flag = 0
        print(cnt)
    except:
        break

Submission status: Accepted

Solution code:
while True:
    T, D, L = map(int, input().split())
    if T == 0 and D == 0 and L == 0: break

    wet=[0]*(T+D)
    for i in range(T):
        if int(input())>=L : 
            wet[i] += 1
            wet[i+D] -= 1
    for i in range(1,T):
        wet[i] += wet[i-1]
    print(sum(x>0 for x in wet[:T-1]))

Submission status: Accepted

Solution code:
import itertools
import operator

def f():
    t, d, l = map(int, input().split())
    if t == d == l == 0:
        return True

    hist = [0] * (10**5*2 + 1)
    for i in range(t):
        x = int(input())
        if x >= l:
            hist[i + 1] += 1
            hist[i + d + 1] -= 1

    print(sum(map(bool, itertools.accumulate(hist[:t], operator.add))))

while not f(): pass

Submission status: Accepted

Solution code:
while(True):
	T,D,L = map(int, input().split())
	if (T+D+L) == 0:break
	x = [int(input()) for i in range(T)]
	count = 0
	lag = 0
	for i in range(T):
		if lag > 0 :
			count += 1
		if x[i] >= L:
			lag = D
		else:
			lag -= 1
	print(count)

Submission status: Accepted

Solution code:
while 1:
  t,d,l=map(int,input().split())
  if t==d==l==0:break
  x=[0]*(t+1)
  for i in range(t):
    s=int(input())
    if s<l:continue
    x[i]+=1
    x[min(i+d,t)]-=1
  y=[0]*t
  y[0]=x[0]
  for i in range(t-1):y[i+1]=y[i]+x[i+1]
  s=0
  for i in y[:-1]:
    if i>0:s+=1
  print(s)

Submission status: Accepted

Solution code:
while True:
	t,d,l = map(int,input().split())
	if t+d+l == 0:break
	lst = []
	for i in range(t):
		x = int(input())
		if x >= l:
			lst.append(1)
		else:
			lst.append(0)
	ans = 0
	sd = 0
	for i,w in enumerate(lst[:-1]):
		if w == 1: 
			ans += 1
			if lst[i+1] != 1:
				sd = d-1
		else:
			if sd != 0:
				ans += 1
				sd -= 1
	
	print(ans)

Submission status: Accepted

Solution code:
while True:
    T, D, L = map(int, input().split())
    if T == D == L == 0:
        break
    X = [int(input()) for i in range(T)]
    S = [0 for i in range(T)]
    for i in range(T):
        if X[i] >= L:
            S[i] += 1
            if i + D < T:
                S[i+D] += -1
    s = 0
    ans = 0
    for i in range(T-1):
        s += S[i]
        if s >= 1:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
"海岸縁"
while True:
    T, D, L = map(int, input().split())
    if T == 0:
        break
    ans = 0
    wet = False
    desserttime = 0
    for i in range(T):
        if wet:
            ans += 1
        x = int(input())
        if x >= L:
            desserttime = D
        elif desserttime > 0:
            desserttime -= 1

        if desserttime == 0:
            wet = False
        else:
            wet = True

    print(ans)

Submission status: Accepted

Solution code:
while True:
    t,d,l=map(int,input().split())
    if t==0:
        break
    ls=[]
    for i in range(t):
        ls.append(int(input()))
    ans=0
    r=0
        
    for j in range(t):
        if ls[j]>=l:
            ans+=1
            if r<d:
                r=d-1
        else:
            if r>0:
                ans+=1
                r-=1
    if ans>0:
        print(ans-1)
    else:
        print(0)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(t,d,l):
        a = [I() for _ in range(t)]
        r = [0] * t
        for i in range(t-1,-1,-1):
            c = a[i]
            if c >= l:
                r[i] = 1
                for j in range(i+1,min(i+d,t)):
                    if r[j] > 0:
                        break
                    r[j] = 1

        return sum(r[:-1])

    while 1:
        n,m,l = LI()
        if n == 0:
            break
        rr.append(f(n,m,l))

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
while True:
    T,D,L = map(int,input().split())
    if T==0 and D ==0 and L == 0:
        break
    x = [int(input()) for i in range(T)]
    beforeflag=0
    flag=0
    total=0
    for i in range(T):
        if x[i]>=L:
            flag=1
            if beforeflag!=D+1 and beforeflag!=0:
                total+=1
        elif x[i]<L and flag>0 and flag<=D:
            flag+=1
            total+=1
        else:
            flag=0
        beforeflag=flag
    print(total)

Submission status: Runtime Error

Solution code:
while 1:
    t, d, l = map(int, raw_input().split())
    rest = ans = 0
    for i in xrange(t):
        x = int(raw_input())
        if l <= x:
            rest = d
        elif rest:
            rest -= 1
        if rest and i < t-1:
            ans += 1
    print ans

Submission status: Runtime Error

Solution code:
while True:
    T,D,L = map(int,input().split())
    if T==0 and D ==0 and L == 0:
        break
    x = [int(input()) for i in range(T)]
    l = [0]*T
    for i in range(T-1):
        if x[i] >= L:
            for j in range(D):
                l[i+j] = 1
    total = 0
    for i in range(T-1):
        total += l[i]

    print(total)

Submission status: Runtime Error

Solution code:
while True:
    T,D,L = map(int,input().split())
    if T==0 and D ==0 and L == 0:
        break
    x = [int(input()) for i in range(T)]
    l = [0]*(T-1)
    for i in range(T-1):
        if x[i] >= L:
            for j in range(D):
                if i+j<T-1:
                    l[i+j] = 1
    total = 0
    for i in range(T-1):
        total += l[i]

    print(total)

Submission status: Runtime Error

Solution code:
while True:
    T,D,L = map(int,input().split())
    if T==0 and D ==0 and L == 0:
        break
    x = [int(input()) for i in range(T)]
    l = [0]*1000
    for i in range(T-1):
        if x[i] >= L:
            for j in range(D):
                if i+j<T-1:
                    l[i+j] = 1
    total = 0
    for i in range(T-1):
        total += l[i]

    print(total)

Submission status: Runtime Error

Solution code:
while True:
    T,D,L = map(int,input().split())
    if T==0 and D ==0 and L == 0:
        break
    x = [int(input()) for i in range(T)]
    l = [0]*(T-1)
    i = 0
    m = 0
    while i<T-1:
         #for i in range(T-1):
        if m < i:
            m = i
        if x[i] >= L and D > m-i:
            tmp=m
            for j in range(D-(tmp-i)):
                if tmp<T-1:
                    l[tmp+j] = 1
                    m += 1
        i+=1
    total = 0
    for i in range(T-1):
        total += l[i]

    print(total)