input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys readline = sys.stdin.readline def root(x): if uf[x] == x: return x else: uf[x] = root(uf[x]) return uf[x] def same(x, y): return root(x) == root(y) def unite(x, y): rx = root(x) ry = root(y) if rx == ry: return uf[rx] = ry N,...
import sys readline = sys.stdin.readline def root(x): if uf[x] == x: return x else: uf[x] = root(uf[x]) return uf[x] def same(x, y): return root(x) == root(y) def unite(x, y): rx = root(x) ry = root(y) if rx == ry: return uf[rx] = ry N,...
p03354
import sys readline = sys.stdin.readline def root(x): if uf[x] == x: return x else: uf[x] = root(uf[x]) return uf[x] def same(x, y): return root(x) == root(y) def unite(x, y): rx = root(x) ry = root(y) if rx == ry: return uf[rx] = ry N,...
import sys readline = sys.stdin.readline def root(x): if uf[x] == x: return x else: uf[x] = root(uf[x]) return uf[x] def same(x, y): return root(x) == root(y) def unite(x, y): rx = root(x) ry = root(y) if rx == ry: return uf[rx] = ry N,...
p03354
# D - Equals from collections import deque N, M = list(map(int, input().split())) p = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(M)] neighbor = [[] for _ in range(N)] for idx in range(M): neighbor[xy[idx][0]-1].append(xy[idx][1]-1) neighbor[xy[idx][1]-1].a...
# D - Equals Union Find N, M = list(map(int, input().split())) p = list(map(int, input().split())) xy = [list(map(int, input().split())) for _ in range(M)] # 負ならそのノードが根かつ絶対値が木の要素数を示す、正なら値のノードが根であることを示す root = [-1] * N # 木の高さを示す rank = [1] * N # インデックスxを与えると、xの根を返す関数 def find_root(x): if root[x] <...
p03354
n, m = list(map(int, input().split())) ps = list(map(int, input().split())) ls = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n self.parents = list(range(n + 1)) self.ranks = [0 for _ in range(n + 1)] def get_root(self...
n, m = list(map(int, input().split())) ps = list(map(int, input().split())) ls = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n self.parents = list(range(n + 1)) self.ranks = [0 for _ in range(n + 1)] def get_root(self...
p03354
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ...
## TLE class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self,...
p03354
N, M = list(map(int, input().split())) p = [int(i) for i in input().split()] graph = [[] for _ in range(N+1)] group = [0]*(N+1) ans = 0 for _ in range(M): x, y = (int(i) for i in input().split()) graph[x].append(y) graph[y].append(x) for i, num in enumerate(p, 1): space = [i] for point in...
N, M = list(map(int, input().split())) p = [int(i) for i in input().split()] graph = [[] for _ in range(N+1)] group = [0]*(N+1) ans = 0 for _ in range(M): x, y = list(map(int, input().split())) graph[x].append(y) graph[y].append(x) for i, num in enumerate(p, 1): space = [i] for point in s...
p03354
def main(): n, m = list(map(int, input().split())) p = [0] + list(map(int, input().split())) cnt = 0 global parent parent = list(range(n+1)) for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if root(i) == root(p[i]...
def main(): n, m = list(map(int, input().split())) p = [0] + list(map(int, input().split())) cnt = 0 global parent parent = list(range(n+1)) for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i]): ...
p03354
def main(): p = [0] + list(map(int, input().split())) cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i]): cnt += 1 print(cnt) def root(x): if parent[x] == x: return x ...
def main(): cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i-1]): cnt += 1 print(cnt) def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[...
p03354
def main(): p = [0] + list(map(int, input().split())) cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i]): cnt += 1 print(cnt) def root(x): if par[x] == x: return x p...
def main(): cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i-1]): cnt += 1 print(cnt) def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] de...
p03354
def main(): cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i-1]): cnt += 1 print(cnt) def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] de...
def main(): cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i in range(1, n+1): if same(i, p[i]): cnt += 1 print(cnt) def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x]...
p03354
def main(): cnt = 0 for _ in range(m): x, y = list(map(int, input().split())) unite(x, y) for i, pi in enumerate(p, 1): if root(i) == root(pi): cnt += 1 print(cnt) def root(x): if parent[x] == x: return x parent[x] = root(parent[x...
def main(): n, m = list(map(int, input().split())) p = list(map(int, input().split())) parent = list(range(n+1)) rank = [0]*(n+1) cnt = 0 def root(x): if parent[x] == x: return x parent[x] = root(parent[x]) return parent[x] def unite...
p03354
import sys input = sys.stdin.buffer.readline def main(): n, m = list(map(int, input().split())) p = list(map(int, input().split())) parent = list(range(n+1)) rank = [0]*(n+1) cnt = 0 def root(x): if parent[x] == x: return x parent[x] = root(parent[x...
import sys input = sys.stdin.buffer.readline def main(): n, m = list(map(int, input().split())) p = list(map(int, input().split())) parent = list(range(n+1)) rank = [0]*(n+1) cnt = 0 def root(x): if parent[x] == x: return x parent[x] = root(parent[x...
p03354
n,m=list(map(int,input().split())) f=lambda x:int(x)-1 p=list(map(f,input().split())) par=[j for j in range(n)] def find(x): if x==par[x]: return x else: par[x]=find(par[x]) return par[x] def union(a,b): ra=find(a) rb=find(b) if ra!=rb: par[ra]=par[rb] for i in range(m): ...
n,m=list(map(int,input().split())) p=list(map(int,input().split())) par=[i for i in range(n)] def find(x): if par[x]==x: return par[x] else: par[x]=find(par[x]) return par[x] def union(x,y): fx=find(x) fy=find(y) if fx!=fy: par[fx]=fy f=lambda x:int(x)-1 for mm in range...
p03354
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n, m = list(map(int, input().split())) p = list( map(int, input().split())) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def root(self, x): if self.parents[x] < 0: ...
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline n, m = list(map(int, input().split())) p = list( map(int, input().split())) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def root(self, x): if self.parents[x] < 0: ...
p03354
def d_equals(N, M, P, S): class UnionFind(object): def __init__(self, N): self.p = list(range(N)) # 初期状態ではi番の頂点の親(parent)はi番 self.rank = [0] * N # 初期状態では全頂点がランク0(何もつながってない) self.size = [1] * N # 初期状態ではどの頂点も連結成分の大きさは1 def find(self, x): # 頂点xが属する連結成分の代表...
def d_equals(N, M, P, S): class UnionFind(object): def __init__(self, N): self.p = list(range(N)) # 初期状態ではi番の頂点の親(parent)はi番 self.rank = [0] * N # 初期状態では全頂点がランク0(何もつながってない) self.size = [1] * N # 初期状態ではどの頂点も連結成分の大きさは1 def find(self, x): # 頂点xが属する連結成分の代表...
p03354
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 class UnionFind: # Reference: https://note.nkmk.me/python-union-find/ def __init__(self, n): self.n = n self.parents = [-1...
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 class UnionFind: # Reference: https://note.nkmk.me/python-union-find/ def __init__(self, n): self.n = n self.parents = [-1...
p03354
tmp = list(map(int,input().split())) n,p,q = tmp[0],tmp[1],tmp[2] cs = [] for i in range(n): cs.append(int(eval(input()))) ans = [sum(cs)] difs = [p * (q-i) - cs[i] for i in range(n)] difs.sort(reverse = True) for i in range(n): ans.append(ans[-1] + 2 * i * p + difs[i]) print((max(ans)))
#着席位置は中央*奥 #問題は「Dinner」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2642&lang=jp) #方針としては、自炊をする回数(0~n)を決め打ちし、それぞれの時の最大値を計算してその最大値を返すことにする #n回自炊するとき、自炊パワーはn-1回自壊する時に比べ最終的に2増える。 #これを考えると、n回自炊する時、高まる自炊パワーによる幸福度の増加分はn*(n+1)となる #したがって、まずリストdifsに「自炊と食堂の幸福度の差分」を全て入れる #これを降順にソートし、n回自炊した時の幸福度の最大値をansに入れていく #...
p01754
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def ...
import sys def MI(): return list(map(int,sys.stdin.readline().rstrip().split())) a,b,c,d = MI() print((max(a*c,a*d,b*c,b*d)))
p02553
a,b,c,d=list(map(int,input().split())) ans=0 if a>=0: if c>=0: ans=b*d elif d>=0: ans=b*d else: ans=a*d elif b>=0: if c>=0: ans=b*d elif d>=0: ans=max(b*d,a*c) else: ans=a*c else: if c>=0: ans=b*c elif d>=0: ...
a,b,c,d=list(map(int,input().split())) ans=max(a*c,a*d,b*c,b*d) print(ans)
p02553
def LI():return list(map(int,input().split())) def II():return int(input()) def yes():return print("Yes") def no():return print("No") INF=float("inf") from collections import deque, defaultdict, Counter from heapq import heappop, heappush from itertools import product, combinations from functools import reduce,...
a,b,c,d=list(map(int,input().split())) print((max(a*c,a*d,b*c,b*d)))
p02553
#!/usr/bin/env python3 import sys input=sys.stdin.readline a,b,c,d=list(map(int,input().split())) ans=-10**18 #x=0 or y=0 if a<=0<=b or c<=0<=d: ans=max(ans,0) #x<0 and y>0 ans=max(ans,b*c) #x>0 and y>0 ans=max(ans,b*d) #x<0 and y<0 ans=max(ans,a*c) #x>0 and y<0 ans=max(ans,a*d) print(ans)
ans=-10**18 a,b,c,d=list(map(int,input().split())) if a<=0<=b or c<=0<=d: ans=0 ans=max(ans,a*c,a*d,b*c,b*d) print(ans)
p02553
a=list(map(int,input().split())) b=a[0]*a[2] c=a[0]*a[3] d=a[1]*a[2] e=a[1]*a[3] print((max(b,c,d,e)))
t=list(map(int,input().split())) print((max(t[0]*t[2],t[0]*t[3],t[1]*t[2],t[1]*t[3])))
p02553
a,b,c,d = list(map(int,input().split())) print((max([a*c,a*d,b*c,b*d])))
a,b,c,d = list(map(int,input().split())) ans=[] for X in [a,b]: for Y in [c,d]: ans.append(X*Y) print((max(ans)))
p02553
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): a, b, c, d = list(map(int, readline().split())) ans = -INF for x in (a, b): for y in (c, d): ans = max(ans, x * y) print(ans) if __name...
a, b, c, d = list(map(int, input().split())) ans = -float("INF") # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます for x in (a, b): for y in (c, d): ans = max(ans, x * y) print(ans)
p02553
a,b,c,d=list(map(int,input().split())) print((max(max(max(a*c,a*d),b*c),b*d)))
a,b,c,d=list(map(int,input().split())) l=[a*c,a*d,b*c,b*d] print((max(l)))
p02553
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(eval(input())) def m_in(type_): return list(map(type_, input().split())) def r_in(n, type_): return [type_(eval(input())) for _ in range(n)] ans = None def absmax(a, b): if abs(a) > abs(b): return a return b def absmin(...
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(eval(input())) def m_in(type_): return list(map(type_, input().split())) def r_in(n, type_): return [type_(eval(input())) for _ in range(n)] ans = None a, b, c, d = m_in(int) ans = max(a*c, a*d, b*c, b*d) print(ans)
p02553
from sys import stdin def main(): _in = [_.rstrip() for _ in stdin.readlines()] a, b, c, d = list(map(int, _in[0].split(' '))) # type:list(int) # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cnt = -float('inf') cnt = max(cnt, a * c) cnt = max(cnt, a * d) cnt = max(cnt, b ...
from sys import stdin def main(): _in = [_.rstrip() for _ in stdin.readlines()] a, b, c, d = list(map(int, _in[0].split(' '))) # type:list(int) # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ans = -float('inf') for _ in [a * c, a * d, b * c, b * d]: ans = max(ans, _) ...
p02553
a, b, c, d = list(map(int, input().split())) answer = 0 if a < 0 and 0 <= b: if c < 0 and 0 <= d: answer = max(a * c, b * d) elif 0 <= c and 0 <= d: answer = b * d elif c < 0 and d < 0: answer = a * c elif 0 <= a and 0 <= b: if c < 0 and 0 <= d: answer = b...
a, b, c, d = list(map(int, input().split())) answer = max(a*c, a*d, b*c, b*d) print(answer)
p02553
a,b,c,d = list(map(int, input().split())) ans = b*d ans = max(ans, a*c) ans = max(ans, b*d) ans = max(ans, a*d) ans = max(ans, b*c) print(ans)
a, b, c, d = list(map(int, input().split())) print((max(a*c, a*d, b*c, b*d)))
p02553
a,b,c,d=list(map(int,input().split())) X=[a,b] Y=[c,d] ans=-10**30 for x in X: for y in Y: if ans<x*y: ans=x*y print(ans)
a,b,c,d=list(map(int,input().split())) print((max(a*c,a*d,b*c,b*d)))
p02553
a, b, c, d = list(map(int, input().split())) if a > 0 and b > 0 and c > 0 and d > 0: print((max(a,b)*max(c,d))) elif a == 0 or b == 0 or c == 0 or d == 0: print((max([a*c, a*d, b*c, b*d]))) else: res = [] for i in range(a, b+1): for j in range(c, d+1): res.append(i*j) print((max(res)))
a, b, c, d = list(map(int, input().split())) print((max([a*c, b*c, a*d, b*d])))
p02553
(X1,X2,Y1,Y2)=list(map(int,input().split())) ans=X2*Y2 ans=max(ans,X1*Y1) ans=max(ans,X1*Y2) ans=max(ans,X2*Y1) print (ans)
(X1,X2,Y1,Y2)=list(map(int,input().split())) ans=max(X2*Y2,X1*Y1,X1*Y2,X2*Y1) print (ans)
p02553
a, b, c, d = list(map(int, input().split())) cnt = [] if a == c and b == d: print((max(a*c, b*d))) exit() else: for i in range(a, b+1): for j in range(c, d+1): cnt.append(i*j) C = sorted(cnt) print((max(C[0],C[-1])))
a, b, c, d = list(map(int,input().split())) if a == c and b == d: print((max(a*c, b*d))) exit() else: print((max(a*c, a*d,b*c,b*d)))
p02553
a,b,c,d=list(map(int,input().split())) if a>=0: if c>=0: print((b*d)) elif c<0 and d>=0: print((b*d)) elif d<0: print((a*d)) elif a<0 and b>=0: if c>=0: print((b*d)) elif c<0 and d>=0: print((max(a*c,b*d))) elif d<0: print((a*c)) ...
a,b,c,d=list(map(int,input().split())) maxxy=max(a*c,a*d,b*c,b*d) print(maxxy)
p02553
a, b, c, d = list(map(int, input().split())) minx = min(a, b) miny = min(c, d) maxx = max(a, b) maxy = max(c, d) print((max(miny * minx, maxx * maxy, maxx * miny, minx * maxy)))
a, b, c, d = list(map(int, input().split())) print((max(a * c, b * d, b * c, a * d)))
p02553
import itertools a,b,c,d=list(map(int,input().split())) ans=-10**9 if b<=0 and d<=0: ans=a*c else : x=list(int(x) for x in range(a,b+1)) y=list(int(y) for y in range(c,d+1)) l=list(itertools.product(x, y)) for i in range(len(l)): if ans<l[i][0]*l[i][1]: ans=...
a,b,c,d=list(map(int,input().split())) ans=max(a*c,a*d,b*c,b*d) print(ans)
p02553
def main(): a, b, c, d = list(map(int, input().split())) if (a <= 0 and b >= 0) or (c <=0 and d >= 0): print((max(a*c, b*d, 0))) else: print((max(a*c, b*d, a*d, b*c))) if __name__ == "__main__": main()
def main(): a, b, c, d = list(map(int, input().split())) if a*b > 0 and c*d > 0 and a*c < 0: print((max(a*d, b*c))) else: print((max(a*c, b*d, 0))) if __name__ == "__main__": main()
p02553
a,b,c,d = list(map(int, input().split())) t = list() ac = a*c bc = b*c ad = a*d bd = b*d t.append(ac) t.append(bc) t.append(ad) t.append(bd) ans = -1 * 10**18 for i in range(4): ans = max(t[i],ans) print(ans)
a,b,c,d = list(map(int, input().split())) ans = max(a*c, a*d, b*c, b*d) print(ans)
p02553
from collections import Counter import copy N = int(eval(input())) D = list(map(int, input().split())) if N == 1: print((min(D[0], 24-D[0]))) exit() D.append(0) D.append(24) c = Counter(D) times = [] p = [] for num, cnt in list(c.items()): if (num == 0 or num == 12) and cnt >= 2: ...
from collections import Counter import copy N = int(eval(input())) D = list(map(int, input().split())) if N == 1: print((min(D[0], 24-D[0]))) exit() D.append(0) D.append(24) # 24-0のパターン c = Counter(D) times = [] p = [] for num, cnt in list(c.items()): if (num == 0 or num == 12) and cnt ...
p03525
from collections import Counter import copy N = int(eval(input())) D = list(map(int, input().split())) if N == 1: print((min(D[0], 24-D[0]))) exit() D.append(0) D.append(24) # 24-0のパターン c = Counter(D) times = [] p = [] for num, cnt in list(c.items()): if (num == 0 or num == 12) and cnt ...
from collections import Counter from collections import defaultdict N = list(map(int, input().split())) D = list(map(int, input().split())) c = Counter(D) # 高橋君と同じ時間帯の人が一人でもいれば、時差の最小は常に0 if c[0] >= 2: print((0)) exit(0) # 高橋君との時差がdの人が3人以上いる場合も、時差の最小は常に0(同じ時間帯の都市に二人以上いることになるから) for ...
p03525
from collections import Counter from collections import defaultdict N = list(map(int, input().split())) D = list(map(int, input().split())) c = Counter(D) # 高橋君と同じ時間帯の人が一人でもいれば、時差の最小は常に0 if c[0] >= 2: print((0)) exit(0) # 高橋君との時差がdの人が3人以上いる場合も、時差の最小は常に0(同じ時間帯の都市に二人以上いることになるから) for ...
from collections import Counter from collections import defaultdict N = list(map(int, input().split())) D = list(map(int, input().split())) c = Counter(D) c[0] += 1 # 高橋君と同じ時間帯の人が一人でもいれば、時差の最小は常に0 if c[0] >= 2: print((0)) exit(0) # 高橋君との時差がdの人が3人以上いる場合も、時差の最小は常に0(同じ時間帯の都市に二人以上いることになる...
p03525
N = int(eval(input())) D = list(map(int, input().split())) if N >= 24: print((0)) else: res = 0 for bit in range(2**N): d = [0 for _ in range(24)] for i in range(N): if (bit >> i) & 1: d[D[i]] += 1 else: d[(24 - D[i]) % ...
N = int(eval(input())) D = list(map(int, input().split())) if N >= 24: print((0)) elif N == 23: d = [0 for _ in range(13)] d[0] = 1 for i in range(N): d[D[i]] += 1 if d[0] > 1 or d[12] > 1: print((0)) else: for i in range(1, 12): if d[i] > 2: ...
p03525
from collections import Counter from itertools import product def solve(LIST): stmp = [i for i, li in enumerate(LIST * 2) if li == 1] S = min(stmp[i] - stmp[i - 1] for i in range(1, len(stmp))) return S n = int(eval(input())) d = Counter(list(map(int, input().split())) + [0]) if any(d[num]...
n = int(eval(input())) d = sorted(list(map(int, input().split())) + [0]) bit, cnt = [0] * 24, 1 for num in d: bit[((num - 12) * cnt + 12) % 24] += 1 cnt *= -1 if any(i > 1 for i in bit): print((0)) exit() ans = [i for i, li in enumerate(bit * 2) if li == 1] s = min(ans[i] - ans[i - 1] for ...
p03525
n = int(eval(input())) d = sorted(list(map(int, input().split())) + [0]) bit, cnt = [0] * 24, 1 for num in d: bit[((num - 12) * cnt + 12) % 24] += 1 cnt *= -1 if any(i > 1 for i in bit): print((0)) exit() ans = [i for i, li in enumerate(bit * 2) if li == 1] s = min(ans[i] - ans[i - 1] for ...
n = int(eval(input())) d = sorted(list(map(int, input().split())) + [0]) ans, cnt = [], 1 for num in d: ans.append(((num - 12) * cnt + 12) % 24) cnt *= -1 ans = sorted(ans + [i + 24 for i in ans]) s = min(ans[i] - ans[i - 1] for i in range(1, len(ans))) print(s)
p03525
n=int(eval(input())) d=list(map(int,input().split())) if n>=24: print((0)) exit() if n==23: print((1)) op=2**n-1 ans=0 for i in range(op): t=[0] for j in range(n): if i&(2**j)>0: t.append(d[j]) else: t.append(24-d[j]) a=10000 for p in ...
n=int(eval(input())) d=list(map(int,input().split())) if n>=24: print((0)) exit() if n>=22: t=[] d.append(0) d.sort() f=1 for i in range(n): if d[i]==d[i+1]: f+=1 else: if f>2: print((0)) exit() ...
p03525
import math from typing import List, Counter, Tuple from collections import Counter from itertools import permutations def read_int() -> int: return int(input().strip()) def read_ints() -> List[int]: return list(map(int, input().strip().split(' '))) INF = 10**9 def solve() -> int: N ...
import math from typing import List, Counter, Tuple from collections import Counter from itertools import permutations def read_int() -> int: return int(input().strip()) def read_ints() -> List[int]: return list(map(int, input().strip().split(' '))) INF = 10**9 def solve() -> int: N ...
p03525
def main(): N = int(input()) D = [int(i) for i in input().split()] ans = 0 cnt = [0]*24 from collections import Counter c = Counter(D) cnt[0] = 1 s = [0]*13 for k, v in c.items(): if v >= 3 or k == 0: ans = 0 return print(ans) elif...
def main(): _ = int(input()) D = [int(i) for i in input().split()] ans = 0 cnt = [0]*24 from collections import Counter c = Counter(D) cnt[0] = 1 s = [0]*13 for k, v in c.items(): if v >= 3: ans = 0 return print(ans) elif k == 0 or...
p03525
import math #import sys #input = sys.stdin.readline def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors def ValueT...
import math #import sys #input = sys.stdin.readline def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) # divisors.sort() return divisors def ValueT...
p03525
from itertools import product import random def solve(n,dl): # n = int(input()) # dl = list(map(int, input().split())) if 0 in dl: return 0 doubles = [] dl1 = [] dl2 = [] for i in range(1,13): i_cnt = dl.count(i) if i_cnt > 2: return 0 ...
n = int(eval(input())) dl = list(map(int, input().split())) if 0 in dl: print((0)) exit() dl.sort() dl1 = [0,24] dl2 = [0,24] for i, d in enumerate(dl): if i%2 == 0: dl1.append(d) dl2.append(24-d) else: dl1.append(24-d) dl2.append(d) dl1.sort() dl2.s...
p03525
N = int(eval(input())) D = [int(d) for d in input().split()] D.append(0) D.sort() ans = 0 time1 = [] time2 = [] for i in range(N+1): if D.count(D[i]) == 2: if D[i] == 0: ans = -1 break time2.append(D[i]) time2.append(24-D[i]) if D.count(D[i]) + D.c...
N = int(eval(input())) D = [int(d) for d in input().split()] D.append(0) D.sort() for i in range(1, N+1): if i%2 == 0: D[i] = 24-D[i] D.sort() ans = min(D[-1], 24-D[-1]) for i in range(N): ans = min(ans, D[i+1]-D[i]) print(ans)
p03525
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(eval(input())) def II(): return list(map(int, input().split())) def III(): return list(map(int, input().split())) def Line(N,num):...
import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(eval(input())) def II(): return list(map(int, input().split())) def III(): return list(map(int, input().split())) def Line(N,num):...
p03525
from collections import Counter import itertools N = int(eval(input())) D = list(map(int, input().split())) M = Counter(D) if max(M.values()) > 2: print((0)) elif 0 in D: print((0)) else: D = [[x, 24-x] for x in D] generator = list(itertools.product([0, 1], repeat=N)) D_gen = [[D[i][g...
from collections import Counter import itertools N = int(eval(input())) D = list(map(int, input().split())) D.append(12) M = Counter(D) if max(M.values()) > 2: print((0)) elif 0 in D: print((0)) elif N > 11: print((1)) else: D.remove(12) D = [[x, 24-x] for x in D] generator = l...
p03525
n,*d=list(map(int,open(0).read().split()));s=sorted l=[0]+s([x if i%2 else 24-x for i,x in enumerate(s(d))])+[24] print((min(j-i for i,j in zip(l,l[1:]))))
_,d=open(0);s=sorted;l=[0]+s([x if i%2else 24-x for i,x in enumerate(s(list(map(int,d.split()))))])+[24];print((min(j-i for i,j in zip(l,l[1:]))))
p03525
_,d=open(0);s=sorted;l=[0]+s([x if i%2else 24-x for i,x in enumerate(s(list(map(int,d.split()))))])+[24];print((min(j-i for i,j in zip(l,l[1:]))))
_,d=open(0);s=sorted;l=s([(24-x,x)[i%2]for i,x in enumerate(s(list(map(int,d.split()))))]);print((min(j-i for i,j in zip([0]+l,l+[24]))))
p03525
n,t=open(0) n=int(n)+1 d=[t if i%2else(24-t)%24for i,t in enumerate([0]+sorted(map(int,t.split())))] print((min(abs(d[i]-d[j])for i in range(n)for j in range(i+1,n))))
_,d=open(0);s=sorted;l=s((24-x,x)[i%2]for i,x in enumerate(s(list(map(int,d.split())))));print((min(j-i for i,j in zip([0]+l,l+[24]))))
p03525
n = int(eval(input())) d = list(map(int, input().split())) h = [0]*13 for i in d: h[i] += 1 ans = 0 def rec(now, state): global ans if now == 13: state.sort() m = float("Inf") for i in range(len(state)): m = min(m, min(abs(state[i-1]-state[i]), 24-abs(state[...
n = int(eval(input())) a = [0]*13 for i in map(int, input().split()): a[i] += 1 ans = 0 if any(i>2 for i in a) or a[0] or a[12]>1: pass else: s = [[0]] for i in range(1, 13): nxt = [] if a[i] == 0: nxt = s elif a[i] == 1: for si in s: ...
p03525
def ans_is_zero(): print((0)) exit(0) def solve(): n=int(eval(input())) if n > 23: ans_is_zero() d=list(map(int,input().split())) for num in d: if num == 0: ans_is_zero() ans=0 N = 1 << n for i in range(N):#left or right t=1 for j in ran...
def ans_is_zero(): print((0)) exit(0) def solve(): n=int(eval(input())) if n > 23: ans_is_zero() d=list(map(int,input().split())) for num in d: if num == 0: ans_is_zero() ans=0 N = 1 << n for i in range(N):#left or right t=1 ret = 100 ...
p03525
import random def ans_is_zero(): print((0)) exit(0) def solve(): n=int(eval(input())) if n > 23: ans_is_zero() d=list(map(int,input().split())) for num in d: if num == 0: ans_is_zero() ans=0 random.shuffle(d) N = 1 << n for i in range(N):#left o...
def ans_is_zero(): print((0)) exit(0) def solve(): n=int(eval(input())) if n > 23: ans_is_zero() d=list(map(int,input().split())) for num in d: if num == 0: ans_is_zero() ans=0 d.sort() N = 1 << n for i in range(N):#left or right t=1 ...
p03525
N = int(eval(input())) D = [0] + list(map(int, input().split())) Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)] # ある都市間の時差の取りうる値は2種類のみ # 先ずはそれを全列挙 candidates = [] for i in range(N+1): for j in range(i+1, N+1): di, dj = D[i], D[j] diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj) cand...
# 想定解法 N = int(eval(input())) D = list(map(int, input().split())) num_time = [0] * 13 num_time[0] = 2 num_time[12] = 1 fixed = [0] unfixed = [] for d in D: num_time[d] += 1 if d == 12: fixed.append(12) if num_time[d] >= 3: print((0)) quit() for t in range(1, 12): if num_time[t]...
p03525
import collections from collections import deque N=int(eval(input())) D=list(map(int,input().split())) c=collections.Counter(D) count0=0 count12=0 zeroflag=0 l=[] if c[12]>0: count12=c[12] if c[0]>0: count0=c[0]+1 #print(l,count0,count12) #print(n) allmax=0 q=deque() l=[] if (count0==0)a...
import collections from collections import deque N=int(eval(input())) D=list(map(int,input().split())) c=collections.Counter(D) count0=0 count12=0 zeroflag=0 l=[] if c[12]>0: count12=c[12] if c[0]>0: count0=c[0]+1 #print(l,count0,count12) #print(n) allmax=0 q=deque() l=[] if (count0==0)a...
p03525
n, c, k = list(map(int, input().split())) t = [] for i in range(n): t.append(int(eval(input()))) t.sort() result = 1 count = 0 for i in range(n): if (t[count] - t[0]) > k or c == count: result += 1 t = t[count:] count = 1 else: count += 1 print(result)
n, c, k = list(map(int, input().split())) t = [int(eval(input())) for i in range(n)] t.sort() result = 1 count = 0 f = 0 for i in range(n): if (t[i] - t[f]) > k or c == count: result += 1 count = 1 f = i else: count += 1 print(result)
p03785
def ii():return int(eval(input())) def iim():return list(map(int,input().split())) def iil():return list(map(int,input().split())) n,c,k = iim() time = [] for _ in range(n): time.append(ii()) time.sort() bus = 0 fst = time[0] ans = 0 for item in time: if bus <= c-1 and item <= k+fst: ...
def ii():return int(eval(input())) def iim():return list(map(int,input().split())) def iil():return list(map(int,input().split())) n,c,k = iim() time = [] for _ in range(n): time.append(ii()) time.sort() bus = 0 fst = time[0] ans = 0 for item in time: if bus <= c-1 and item <= k+fst: ...
p03785
import math N, C, K = list(map(int, input().split())) t_dic = {} for j in range(N): t_num = int(eval(input())) num = t_dic.get(t_num, 0) t_dic[t_num] = num + 1 t_list = sorted(t_dic.keys()) removed_man_dic = {} total_car = 0 for i, t in enumerate(t_list): limit = t + K limit_num = t_...
N, C, K = list(map(int, input().split())) t_sorted = [int(eval(input())) for _ in range(N)] t_sorted.sort() car = 0 passenger = 0 target_t, limit = 0, 0 for i, t in enumerate(t_sorted): if target_t == 0: target_t = t limit = t + K passenger += 1 if passenger == C: car +...
p03785
N, C, K = list(map(int, input().split())) T = [] for i in range(N): T.append(int(eval(input()))) sorted_T = sorted(T) bus_count = 1 pas_count = 0 bus_start = sorted_T[0] for t in sorted_T: if pas_count == C or t - bus_start > K: bus_count += 1 pas_count = 0 bus_start = t ...
N, C, K = list(map(int, input().split())) flag = True pass_num = 0 count = 1 for t in sorted([int(eval(input())) for _ in range(N)]): if flag: first_pass_time = t flag = False if t - first_pass_time > K or pass_num == C: first_pass_time = t pass_num = 0 count +...
p03785
import bisect N, C, K = list(map(int, input().split())) T = sorted([int(eval(input())) for i in range(N)]) i = 0 ans = 0 while T: ans += 1 check = T[0] + K people = bisect.bisect_right(T, check) if people > C: del T[:C] else: del T[:people] print(ans)
import bisect N, C, K =list(map(int, input().split())) T = sorted([int(eval(input())) for i in range(N)]) ans = 0 front = 0 while front < N: standard = T[front] + K front = min(bisect.bisect_right(T, standard), front+C) ans += 1 print(ans)
p03785
# AGC011A - Airport Bus import sys input = sys.stdin.readline def main(): N, C, K = tuple(map(int, input().rstrip().split())) T = sorted(map(int, [input().rstrip() for _ in range(N)])) ans, cur, cnt = 0, T[0] + K, 0 for i in T: if i > cur or cnt == C: # need a new bus cur...
# AGC011A - Airport Bus def main(): N, C, K, *T = list(map(int, open(0).read().split())) T.sort() ans, cur, cnt = 0, T[0] + K, 0 for i in T: if i > cur or cnt == C: # need a new bus cur = i + K cnt = 1 ans += 1 else: # ride on the current o...
p03785
N,C,K = list(map(int,input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() i = 0 ans = 0 while i < N: tmp = i+1 while tmp < N: if tmp < i+C and T[tmp] <= T[i]+K: tmp += 1 else: break ans += 1 i = tmp print(ans)
N, C, K = list(map(int, input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() T.append(10**12) ans = 0 now = T[0] i = 0 while i < N: ans += 1 num = 0 while i < N and T[i] <= now+K and num < C: num += 1 i += 1 now = T[i] print(ans)
p03785
import sys input = sys.stdin.readline N,C,K = list(map(int,input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() answer = 0 first = -K rest = C for t in T: if first + K >= t and rest > 0: # 乗れる rest -= 1 continue # 乗れない answer += 1 first = t ...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # greedy N,C,K,*T = list(map(int,read().split())) T.sort() bus_t = -K - 100 bus_c = C answer = 0 for t in T: bl = (bus_t + K >= t) and (bus_c + 1 <= C) if bl: bus_c +=...
p03785
import bisect kyaku, teiin, jikan = list(map(int, input().split(" "))) a=sorted([(int)(eval(input())) for i in range(kyaku)]) count = 0 while(True): #print(a) if len(a) > teiin: if a[0] + jikan >= a[teiin]: a = a[teiin:] else: a = a[bisect.bisect_left(a, a[0] + jikan):] else: i...
n,c,k = list(map(int ,input().split(" "))) t = sorted([int(eval(input())) for i in range(n)]) total = 0 count = 0 while(count != n): temp = 0 #print(count, total) for i in range(c): if count + i >= n: #print("乗りたい人数を全部さばいた") if t[-1] - t[count] <= k: #print("最後の人全員載せる") ...
p03785
#!/usr/bin python3 # -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right def main(): N,C,K = list(map(int, input().split())) Ti = list(int(eval(input())) for _ in range(N)) Ti.sort() ret = 0 # print(Ti) while len(Ti)>0: Tto = K + Ti[0] Ti = Ti[min(C,b...
#!/usr/bin python3 # -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right def main(): N,C,K = list(map(int, input().split())) Ti = list(int(eval(input())) for _ in range(N)) Ti.sort() i = 0 ret = 0 while i<N: ret += 1 s = i Ts = Ti[i] ...
p03785
def main(): n, c, k, *t = list(map(int, open(0).read().split())) t = sorted(t) u = tuple(t) count = 0 i = 0 while i < n: x = u[i] + k y = min(i + c - 1, n - 1) while True: if u[y] <= x: break y -= 1 count +=...
def main(): n, c, k, *t = list(map(int, open(0).read().split())) t = sorted(t) u = tuple(t) cnt = 1 p, l = 0, u[0] + k for v in t: if v <= l and p < c: p += 1 else: cnt += 1 l = v + k p = 1 print(cnt) if __na...
p03785
def main(): n, c, k, *t = list(map(int, open(0).read().split())) t = sorted(t) u = tuple(t) cnt = 1 p, l = 0, u[0] + k for v in t: if v <= l and p < c: p += 1 else: cnt += 1 l = v + k p = 1 print(cnt) if __na...
def main(): n, c, k, *t = list(map(int, open(0).read().split())) t.sort() u = tuple(t) cnt = 1 p, l = 0, u[0] + k for v in t: if v <= l and p < c: p += 1 else: cnt += 1 p = 1 l = v + k print(cnt) if __name__ ...
p03785
import bisect def resolve(): n, c, k = list(map(int, input().split())) t = list(int(eval(input())) for _ in range(n)) t.sort() ans = 0 while t: candidates = bisect.bisect_left(t, t[0] + k) # candidates = len([tj for tj in t if tj <= t[0] + k]) num = min(c, candid...
def resolve(): n, c, k = list(map(int, input().split())) t = list(int(eval(input())) for _ in range(n)) t.sort() ans = 1 limit = t[0] + k bus = 0 for i in range(n): bus += 1 if t[i] > limit or bus > c: limit = t[i] + k ans += 1 ...
p03785
import sys def input(): return sys.stdin.readline()[:-1] N, C, K = list(map(int, input().split())) T = [0]*N for i in range(N): T[i] = int(eval(input())) T.sort() ans = 0 bus_time = -1 bus_num = 0 for i in range(N): # 新しいバス if bus_time == -1: bus_time = T[i] bu...
import sys def input(): return sys.stdin.readline()[:-1] N, C, K = list(map(int, input().split())) T = [0]*N for i in range(N): T[i] = int(eval(input())) T.sort() ans = 1 bus_time = T[0] bus_num = 0 for i in range(N): if T[i] <= bus_time+K and bus_num < C: # 止まっているバスに乗る ...
p03785
N, C, K = [int(x) for x in input().split()] T = [int(eval(input())) for _ in range(N)] T.sort() depart = T[0] + K # 出発時刻 passenger = 0 # 乗客数 bus = 1 for i in range(N): if passenger >= C or depart < T[i]: # すでに満員または待ち時間オーバー bus += 1 passenger = 1 depart = T[i] + K else: ...
import sys input = sys.stdin.readline N, C, K = [int(x) for x in input().split()] T = [int(eval(input())) for _ in range(N)] T.sort() depart = T[0] + K # 出発時刻 passenger = 0 # 乗客数 bus = 1 for i in range(N): if passenger >= C or depart < T[i]: # すでに満員または待ち時間オーバー bus += 1 passenger = 1 ...
p03785
N,C,K = list(map(int,input().split())) T = [] for i in range(N): T.append(int(eval(input()))) flag = 0 ans = 1 T = sorted(T) while flag == 0: if C < len(T) or T[-1]-T[0]>=K: if C < len(T): if T[0]+K<T[C-1]: T = [i for i in T if i > T[0]+K] ans +=...
N,C,K=list(map(int,input().split())) T=[] for i in range(N): p=int(eval(input())) T.append(p) ans = 1 T = sorted(T) ind = 0 for i in range(len(T)): if T[i] > T[ind]+K: ans += 1 ind = i elif i >= ind + C: ans += 1 ind = i print(ans)
p03785
import collections n, c, k = list(map(int, input().split())) t = [int(eval(input())) for i in range(n)] t.sort() passenger = 0 departure_limit = t[0] + k bus_cnt = 0 for T in t: if passenger+1 > c or T > departure_limit: departure_limit = T+k passenger = 1 bus_cnt += 1 ...
n, c, k, *t = list(map(int, open(0).read().split())) t.sort() tmp = 0 cnt = 0 limit = t[0] + k for time in t: if tmp == c or time > limit: limit = time + k tmp = 1 cnt += 1 else: tmp += 1 print((cnt + 1))
p03785
n,c,k = list(map(int, input().split())) t = [int(eval(input())) for _ in range(n)] t.sort() T = 0 cnt = 0 ans = 0 for i in range(n): if cnt == 0: #誰も待っていない T = t[i] + k cnt += 1 elif t[i] <= T: cnt += 1 elif t[i] > T: ans += 1 cnt = 1 T = t[i] + k if cnt == c: ans ...
n,c,k = list(map(int, input().split())) t = sorted(list(int(eval(input())) for _ in range(n))) #Ti以上Ti+k以下のバスに乗る #定員はC人 T = 0 cnt = 0 bus = 0 for i in range(n): if cnt == 0: cnt += 1 T = t[i] + k elif T >= t[i]: cnt += 1 elif T < t[i]: bus += 1 cnt ...
p03785
n,c,k = [int(x) for x in input().split()] t = [] for _ in range(n): t.append(int(eval(input()))) t.sort() ans = 0 tmp = {"f": 0, "num": c} for x in t: if tmp["f"] >= x and tmp["num"] > 0: tmp["num"] -= 1 else: ans += 1 tmp["num"] = c-1 tmp["f"] = x+k pri...
n,c,k = [int(x) for x in input().split()] t = [int(eval(input())) for _ in range(n)] t.sort() bus = c f_bus = 0 ans = 0 for i in range(n): if t[i] > f_bus or bus == 0: ans += 1 f_bus = t[i]+k bus = c-1 else: bus -= 1 print(ans)
p03785
N, C, K = list(map(int, input().split())) T = [int(eval(input())) for i in range(N)] T.sort() answer = 0 while len(T) > 0: limit = T[0] + K counter = 0 while counter < C: if len(T) == 0: break if T[0] > limit: break del T[0] counter += 1 ...
N, C, K = list(map(int, input().split())) T = [int(eval(input())) for i in range(N)] T.sort() limit = T[0] answer = 1 counter = 1 for i in range(1,N): if T[i] - limit > K or counter == C: limit = T[i] counter = 1 answer += 1 else: counter += 1 print(answer)
p03785
def main() -> None: n, c, k = list(map(int, input().split())) t = [int(eval(input())) for _ in range(n)] ans = wait_start = wait_people = 0 for ti in sorted(t): if ti - wait_start > k or wait_people == c: wait_people = 0 wait_people += 1 if wait_people == ...
import sys def main() -> None: n, c, k = list(map(int, input().split())) t = [int(sys.stdin.readline()) for _ in range(n)] ans = wait_start = wait_people = 0 for ti in sorted(t): if ti - wait_start > k or wait_people == c: wait_people = 0 wait_people += 1 ...
p03785
N, C, K = list(map(int, input().split())) T = [] for _ in range(N): T.append(int(eval(input()))) T.sort() buss = [] x, *T = T bus = [x] while T: while T: t, *T = T if t <= x + K and len(bus) < C: bus.append(t) else: x = t buss.append...
N, C, K = list(map(int, input().split())) T = sorted([int(eval(input())) for _ in range(N)]) x = T[0] p = 1 b = 1 for i in range(1, N): if T[i] <= x + K and p < C: p += 1 else: x = T[i] b += 1 p = 1 print(b)
p03785
n, c, k = list(map(int, input().split())) arr = [eval(input()) for i in range(n)] arr.sort() res = 1 start = arr[0] cur = c for pas in arr: if c == 0: c = cur start = pas res += 1 if pas <= start + k: c -= 1 else: res += 1 c = cur -1 start = pas print(res)
n, c, k = list(map(int, input().split())) arr = [eval(input()) for i in range(n)] arr.sort() res = 1 start = arr[0] cur = c for pas in arr: if c == 0: c = cur - 1 start = pas res += 1 continue if pas <= start + k: c -= 1 else: res += 1 c = cur -1 start = pas print(res)
p03785
n,c,k = list(map(int,input().split())) t = list(int(eval(input())) for i in range(n)) t.sort() ans = 0 i = 0 while i < n: a = t[i] j = i + 1 z = 1 for j in range(i+1,min(i+c,n)): if a+k >= t[j]: z += 1 else: break i += z ans += 1 print(ans)
n,c,k = list(map(int,input().split())) t = list(int(eval(input())) for i in range(n)) t.sort() ans = 0 x = t[0] y = 1 for i in range(1,n): if x+k < t[i] or y >= c: ans += 1 x = t[i] y = 1 else: y += 1 print((ans+1))
p03785
N, C, K = list(map(int, input().split())) T = sorted([int(eval(input())) for i in range(N)]) array = [T[0]] arrays = [] s = 0 for i in range(1, len(T)): if ((T[i] - T[s]) <= K) and len(array) < C: array.append(T[i]) else: arrays.append(array) array = [T[i]] s = i prin...
N, C, K = list(map(int, input().split())) T = sorted([int(eval(input())) for i in range(N)]) s = 0 array = [T[0]] arrays = [] for i in range(1, N): if ((T[i] - T[s]) <= K) and (len(array) < C): array.append(T[i]) else: arrays.append(array) array = [T[i]] s = i print((...
p03785
N, C, K = list(map(int, input().split())) T = [] for _ in range(N): T.append((int(eval(input())), False)) T.append((T[-1][0] + K, True)) T.sort(key=lambda x: (x[0], x[1])) ans = 0 arrived = 0 head = 0 for t, bo in T: if arrived == 0 and not bo: head = t arrived += not bo if (bo ...
N, C, K = list(map(int, input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() ans = 0 first = T[0] arrived = 0 for t in T: if first + K < t or arrived == C: ans += 1 arrived = 0 first = t arrived += 1 print((ans + (arrived > 0)))
p03785
# 乗せれるだけ乗っけるのがいいと思うだけなんだけどどうなんでしょう # なんか実装しにくい 世界一プログラミングが下手 # 二重whileなんてやるからだ forでいいやろ n, c, k = list(map(int, input().split())) ans = 0 arr = sorted([int(eval(input())) for _ in range(n)]) cur_passenger = 0 limit = arr[0] + k for i in range(n): if cur_passenger < c and arr[i] <= limit: cur_passe...
n, c, k = list(map(int, input().split())) t = sorted([int(eval(input())) for _ in range(n)]) ans = 1 passenger = 0 limit = t[0] + k for p in t: if passenger < c and p <= limit: passenger += 1 else: ans += 1 passenger = 1 limit = p + k print(ans)
p03785
N, C, K = list(map(int, input().split())) passengers = sorted([int(eval(input())) for i in range(N)]) res = {} for p in passengers: key = False for k in list(res.keys()): if k <= p and p <= k + K and res[k] <= C - 1: res[k] += 1 key = True break if n...
N, C, K = list(map(int, input().split())) passengers = sorted([int(eval(input())) for i in range(N)]) res = 0 bus_time = passengers[0] bus_count = C for p in passengers: if bus_count == 0 or p - bus_time > K: res += 1 bus_time = p bus_count = C - 1 else: bus_count -=...
p03785
# -*- coding: utf-8 -*- #---------- N,C,K = list(map(int, input().rstrip().split())) T_list = [int(input().strip()) for _ in range(N)] T_list.sort() #---------- num_bus=0 i=0 while i < len(T_list): # Busに何人乗せられるか時刻を比較 member_bus=0 break_flg=False for j in range(C): if (i+j...
# -*- coding: utf-8 -*- #---------- N,C,K = list(map(int, input().rstrip().split())) T_list = [int(input().strip()) for _ in range(N)] T_list.sort() #---------- num_bus=0 i=0 while i < len(T_list): # Busに何人乗せられるか時刻を比較 member_bus=0 break_flg=False for j in range(C): if (i+j...
p03785
from collections import Counter n, c, k = list(map(int, input().split())) time_people = Counter([int(eval(input())) for _ in range(n)]) times = sorted(time_people.keys()) ans = 0 left = 0 right = 0 while time_people[times[-1]] > 0: space = c while times[left] + k >= times[right] and space > 0: ...
n, c, k = list(map(int, input().split())) T = sorted([int(eval(input())) for _ in range(n)]) ans = 1 first = T[0] pas = 0 for t in T: pas += 1 if t > first + k or pas > c: ans += 1 pas = 1 first = t print(ans)
p03785
n,c,k=list(map(int,input().split())) t=[int(eval(input())) for _ in range(n)]+[10**10] t.sort() b=1 p=0 while p<n: l=t[p]+k pp=1 f=1 while pp<c and f: p+=1 if t[p]<=l: pp+=1 if pp==c: p+=1 else: f=0 if p<n: b+=1 print(b)
n,c,k=list(map(int,input().split())) t=[int(eval(input())) for _ in range(n)]+[10**10] t.sort() b=1 p=0 if c==1: print(n) exit() while p<n: l=t[p]+k pp=1 f=1 while pp<c and f: p+=1 if t[p]<=l: pp+=1 if pp==c: p+=1 else: f=0 if p<n: b+=1 print...
p03785
n,c,k = list(map(int, input().split())) Ts = [int(eval(input())) for i in range(n)] + [10**10] Ts = sorted(Ts) ans = 0 cnt = 1 flg = 0 prev = Ts[0] for i in range(1,len(Ts)): now = Ts[i] if now - prev <= k: cnt += 1 else: ans += 1 cnt = 1 prev = Ts[i] if ...
import sys input = sys.stdin.readline n,c,k = list(map(int, input().split())) ts = [int(eval(input())) for i in range(n)] ts.sort() cnt = 0 ans = 0 end = -1 for i, t in enumerate(ts): if end < t: cnt = 1 ans += 1 end = t + k else: # t <= end cnt += 1 if cnt > ...
p03785
n, c, k = list(map(int, input().split())) t = [int(eval(input())) for _ in range(n)] t = sorted(t) cnt_bus = 0 i = 0 while i < n: cnt_rider = 0 l, r = i, min(i + c - 1, n - 1) while l <= r:#適当なmidを求める mid = (l + r) // 2 if t[mid] > t[i] + k: r = mid - 1 else...
n, c, k = list(map(int, input().split())) ts = [int(eval(input())) for _ in range(n)] ts = sorted(ts) cnt = 0 rider = 0 limit = -1 for t in ts: if (rider == c) or not(t <= limit <= (t + k)): cnt += 1 limit = (t + k) rider = 1 else: rider += 1 print(cnt)
p03785
N, C, K = list(map(int, input().split())) T = [0 for _ in range(N)] for i in range(N): T[i] = int(eval(input())) T = sorted(T) ans = 0 while T != []: cnt = 0 for i in range(len(T)): cnt += 1 if T[i] - T[0] > K or cnt > C: T = T[i:] ans += 1 ...
N, C, K = list(map(int, input().split())) T = [0 for _ in range(N)] for i in range(N): T[i] = int(eval(input())) T = sorted(T) flag = 0 cnt = 0 ans = 0 for i in range(len(T)): time = T[i] - T[flag] cnt += 1 if time > K or cnt > C: flag = i cnt = 1 ans += 1 print(...
p03785
N, C, K = list(map(int, input().split())) users = [] for i in range(N): users.append(int(eval(input()))) users = sorted(users, reverse=False) ans = 0 pos = 0 start = 0 while True: count = 0 if pos == N: break start = users[pos] # print("start:{}".format(start))...
N, C, K = list(map(int, input().split())) users = [] for i in range(N): users.append(int(eval(input()))) users = sorted(users, reverse=False) ans = 0 pos = 0 start = 0 while True: count = 0 if pos == N: break start = users[pos] # print("start:{}".format(start))...
p03785
N, C, K = list(map(int, input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() num_track = 0 i = 0 while i < N: L = T[i] if i + C + 1 < N: kouho = T[i:i+C] # T[i],...,T[i+C-1] else: kouho = T[i:] # <= L + K num = 0 for j in range(len(kouho)): if kouho[j] - L <= K: num ...
N, C, K = list(map(int, input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() res = 0 i = 0 while i < N: res += 1 Left = i while (i < N and T[i] - T[Left] <= K and i - Left + 1 <= C): i += 1 print(res)
p03785
from collections import deque n,c,k = list(map(int, input().split())) t = [int(eval(input())) for _ in range(n)] tk = [(ti, ti+k) for ti in t] tk.sort(key=lambda x:x[1]) tk = deque(tk) #print(tk) ans = 0 # tkが尽きるまで while tk: _, bus = tk[0] # バスの時刻より早く来ている客をカウント cnt = 0 while (...
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.re...
p03785
from bisect import bisect_right N,C,K = list(map(int,input().split())) T = sorted([int(eval(input())) for _ in range(N)]) cnt = 0 cur = 0 while cur<N: i = min(cur+C,N)-1 if T[i]-T[cur]<=K: cnt += 1 cur = i+1 else: i = bisect_right(T,T[cur]+K)-1 cnt += 1 c...
from bisect import bisect_right N,C,K = list(map(int,input().split())) T = sorted([int(eval(input())) for _ in range(N)]) cur = 0 cnt = 0 while cur<N: ind = bisect_right(T,T[cur]+K) if ind-cur<=C: cnt += 1 cur = ind else: cnt += 1 cur += C print(cnt)
p03785
def solve(): N, C, K = list(map(int, input().split())) T = [int(eval(input())) for _ in range(N)] T.sort() cnt = 0 ans = 1 for i in range(N-1): if i==0: t = T[0] cnt += 1 if T[i+1]>t+K or cnt>=C: ans += 1 cnt = 0 t = T[i+1] return ans print((solve()))
def solve(): N, C, K = list(map(int, input().split())) ans = 1 cnt = 0 T = [int(eval(input())) for _ in range(N)] T.sort() for i in range(N): if i==0: now = T[i] cnt += 1 if now+K<T[i] or cnt>C: ans += 1 cnt = 1 if i<N-1: now = T[i] return ans pr...
p03785
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, c, k = list(map(int, readline().split())) t = sorted([int(readline()) for i in range(n)]) cnt = 0 ans = 1 time = t[0] + k for i in range(n): if cnt >= c ...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, c, k = list(map(int, readline().split())) t = [int(readline()) for _ in range(n)] t.sort() ans = 1 tmp = [t[0], 0] for tt in t: if tmp[0] + k < tt or tmp...
p03785