(n,k) = map(int,input().strip().split(' ')) a = list(map(int,input().strip().split(' '))) a = [0]+a q = [0for i inrange(n+2)] dp = [1<<60for i inrange(n+2)] dp[0] = a[0] tt = -1 hh = 0 for i inrange(n): if tt>=hh and i-q[hh]+1 > k:hh+=1 while tt>=hh and dp[q[tt]] >= dp[i]:tt-=1 tt+=1 q[tt] = i dp[i+1] = a[i+1]+dp[q[hh]]
ans = 1<<60 for i inrange(n-k+1,n+1): ans =min(ans,dp[i]) print(ans)
N,L = map(int,input().strip().split()) li = [[] for i inrange(N+2)] for i inrange(1,N+1): tp = list(map(int,input().strip().split())) tp.pop(0) for j in tp: li[j].append(i)
Q = list(map(int,input().strip().split()))
for i inrange(1,Q[0]+1): st = set() cnt = 0 qu = deque() qu.append((Q[i],0)) st.add(Q[i]) whilelen(qu): tp = qu.popleft() if tp[1] >= L: continue # print(li[tp[0]]) for nx in li[tp[0]]: if nx notin st: st.add(nx) qu.append((nx,tp[1]+1)) print(len(st)-1)
from collections import deque from sys import stdin import copy
defbfs(li,i,j,st,cnt): dx,dy = [0,1,0,-1],[1,0,-1,0] qu = deque() qu.append((i,j)) st[(i,j)]=cnt whilelen(qu): tp = qu.popleft() for i inrange(4): x, y = tp[0] + dx[i] ,tp[1] + dy[i] if x < 0or y<0or x>=len(li[0]) or y>=len(li[0]): continue if (x,y) in st:continue if li[x][y] == '.':continue st[(x,y)] = cnt qu.append((x,y))
deffun(li,st): cnt = 0 for i inrange(len(li[0])): for j inrange(len(li[0])): if li[i][j] == '.': continue if (i,j) notin st: cnt+=1 bfs(li,i,j,st,cnt) return cnt
N = int(input()) li = [[] for i inrange(N+2)] li2 = [[] for i inrange(N+2)] for i inrange(N): li[i] = list(map(str,input())) li2[i] = copy.deepcopy(li[i])
stt = set() dc = dict() cnt = fun(li,dc)
for i inrange(len(li[0])): for j inrange(len(li[0])): if li[i][j]=='#': if li[i+1][j] == '.'or li[i][j+1] == '.'or\ li[i-1][j] == '.'or li[i][j-1] == '.' : li2[i][j] = '.' else: stt.add(dc[(i,j)]) print(cnt - len(stt))
from collections import deque from sys import stdin import copy
n,m,k = map(int,stdin.readline().strip().split())
li = [[] for i inrange(n)] for i inrange(n): li[i] = list(map(int,stdin.readline().strip().split()))
st = set() defdfs(i,j,res,s): global st global li if res==0: st.add(s) return dx,dy = [0,1,0,-1],[-1,0,1,0] for _ inrange(4): x,y = i+dx[_],j+dy[_] if0<= x < len(li) and0<= y < len(li[0]): dfs(x,y,res-1,s+str(li[x][y]))
for i inrange(n): for j inrange(m): dfs(i,j,k,str(li[i][j]))
import sys sys.setrecursionlimit(1000000) defcheck(): global ans a , b, c = 0 ,0,0 s = ''.join(str(i) for i in path) for i inrange(1,9): a = int(s[:i]) if a > n:break for j inrange(8,i,-1): b = int(s[i:j]) c = int(s[j:]) if b<c:break if b%c:continue if a+b/c == n: ans += 1 defdfs(u): if u==9: check() return for i inrange(1,10): ifnot st[i]: st[i] = True path.append(i) dfs(u+1) path.pop() st[i] = False
n = int(input()) ans = 0 st = [False]*10 path = [] dfs(0) print(ans)