input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): n=I(...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): n=I(...
p03673
n = int(eval(input())) a = input().split() b = [] for i in range(n): if n%2 == 0: if i%2== 1: b.insert(0,a[i]) else: b.append(a[i]) else: if i%2== 0: b.insert(0,a[i]) else: b.append(a[i]) result= ' '.join(b) print(result)
n = int(eval(input())) num = list(map(str,input().split())) a,b = [],[] result = '' for i in range(n): if i%2 == 0: a.append(num[i]) else: b.append(num[i]) if n%2 ==1: result = ' '.join(a[::-1]) result += ' ' + ' '.join(b) else: result = ' '.join(b[::-1]) result += ' ' + ' '.join(a) p...
p03673
n = int(eval(input())) A = input().split() B = [] for a in A: B.append(a) B.reverse() print((' '.join(B)))
n = int(eval(input())) a = input().split() if n % 2 != 0: r, l = a[1::2], a[::2] else: r, l = a[::2], a[1::2] l.reverse() print((' '.join(l + r)))
p03673
n=int(eval(input())) a=list(map(int, input().split())) b=[] for i in range(n): b.append(str(a[i])) b=b[::-1] print((' '.join(b)))
n=int(eval(input())) a=list(map(int, input().split())) b=[0 for _ in range(n)] if n%2!=0: for i in range(n): if i%2==0: b[n//2-i//2]=str(a[i]) else: b[n//2+i//2+1]=str(a[i]) else: for i in range(n): if i%2==0: b[n//2+i//2]=str(a[i]) ...
p03673
n = int(eval(input())) a = list(map(str, input().split())) b = [] for i in range(n): if i % 2 == 0: b.append(a[i]) else: b = [a[i]] + b if n % 2 == 1: b.reverse() print((' '.join(map(str, b))))
n = int(eval(input())) a = input().split() print((' '.join(a[-1::-2] + a[(n % 2)::2])))
p03673
n = int(eval(input())) a = list(input().split()) ans = a[0] for i in range(n): if i%2 == 0 and i != 0: ans = ans + ' ' + a[i] elif i%2 != 0: ans = a[i] + ' ' + ans if n%2 != 0 and n != 1: print((ans[::-1])) else: print(ans)
n = int(eval(input())) a = list(input().split()) a1 = ['']*(n//2 + n%2) a2 = ['']*(n//2) for i in range(n): if i%2 == 0: a1[i//2] = a[i] else: a2[-i//2] = a[i] if n%2 != 0 and n != 1: ans = ' '.join(a1[::-1]) + ' ' + ' '.join(a2[::-1]) elif n%2 == 0: ans = ' '.join(a2) + ' ' + ' '.join(a1) else...
p03673
def C_pushpush(x): from collections import deque # insertをリストの先頭に行うと、リストの要素の再配置に時間がかかる n = int(x[0]) a = deque(x[1:]) b = deque([]) n_parity = n & 1 for i in range(n): if n_parity == (i + 1) & 1: # n,iのパリティが一致 b.appendleft(a[i]) else: ...
def c_pushpush(N,A): from collections import deque # insertをリストの先頭に行うと、リストの要素の再配置に時間がかかる b = deque([]) n_parity = N & 1 for i in range(N): if n_parity == (i + 1) & 1: # n,iのパリティが一致 b.appendleft(A[i]) else: b.append(A[i]) ans = ' '.jo...
p03673
def c_pushpush(N, A): from collections import deque ans = deque([]) # リストの先頭への挿入はO(要素数)なので n_parity = N & 1 for i, a in enumerate(A, 1): if n_parity == i & 1: ans.appendleft(a) else: ans.append(a) return ' '.join(map(str, ans)) N = int(eval(input(...
def c_pushpush(): # Aの奇数番目の要素と偶数番目の要素をそれぞれ一塊にすることは変わらない。 # ただし、どちらを左右にするかは N の偶奇によって変わる N = int(eval(input())) A = [int(i) for i in input().split()] return ' '.join(map(str, A[int(N % 2 == 0)::2][::-1] + A[int(not N % 2 == 0)::2])) print((c_pushpush()))
p03673
n=int(input()) b=[] k=0 for i in map(int, input().split()): if k%2==0: b.append(i) k+=1 else: b.insert(0,i) k+=1 if n%2!=0: b=b[::-1] print(*b,sep=" ")
N=int(input()) A=list(map(int,input().split())) print(*A[::-2],end=" ") print(*A[N%2::2])
p03673
N = int(input()) S = list(map(int, input().split())) b = [] for i in range(N): if (i + N) % 2 == 0: b.append(S[i]) else: b = [S[i]] + b[:] for i in range(N - 1): print(b[i], end = ' ') print(b[N - 1])
N = int(input()) S = list(map(int, input().split())) b = [0 for i in range(N)] if N % 2 == 0: for i in range(N): if i % 2 == 0: b[(N + i) // 2] = S[i] else: b[(N - i) // 2] = S[i] else: b[N // 2] = S[0] for i in range(1, N): if i % 2 == 1: b[(N + i) // 2] = S[i] els...
p03673
n, m = list(map(int, input().split())) ab=[0]*m for i in range(m): ab[i] = [int(x) for x in input().split()] ab.sort() ans = 1 key = ab[0][1] for i in range(m): if ab[i][0] >= key: ans += 1 key = ab[i][1] elif ab[i][1] < key: key = ab[i][1] print(ans)
n, m = list(map(int, input().split())) bridge = [None]*m for i in range(m): a, b = list(map(int, input().split())) bridge[i] = [b, a] ans = 0 bridge.sort() sub = -1 ans = 0 for v in bridge: b, a = v[0], v[1] if a >= sub: sub = b ans += 1 print(ans)
p03295
n, m = list(map(int, input().split())) wars = {} for i in range(m): a, b = list(map(int, input().split())) if a in list(wars.keys()): wars[a].append(b) else: wars[a] = [b] cuts = 0 antis = [] for i in range(1, n): if i in list(wars.keys()): antis.append(min(wars[i])) if i + 1 in a...
n, m = list(map(int, input().split())) wars = {} for i in range(m): a, b = list(map(int, input().split())) if a in list(wars.keys()): wars[a] = min(wars[a], b) else: wars[a] = b cuts = 0 antis = 10**6 for i in range(1, n): if i in list(wars.keys()): antis = min(antis, wars[i]) if ...
p03295
n,m = list(map(int, input().split())) ans = 0 ba = [[0 for _ in range(2)] for _ in range(m)] for i in range(m): a,b = list(map(int, input().split())) ba[i][0] = b ba[i][1] = a ba.sort() br = 0 for b,a in ba: #if bridge[(a-1):] != 0: if not (a < br < b): #bridge[b-2] = 0 ...
N,M = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(M)] ab.sort() ans = 1 l, r = ab[0][0], ab[0][1] for a,b in ab[1:]: if a < r: l = max(l,a) r = min(r,b) else: ans += 1 l = a r = b print(ans)
p03295
N,M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort() l,r = 1,N ans = 1 for a,b in AB: if r <= a: ans += 1 l,r = a,b else: l = max(l,a) r = min(r,b) print(ans)
N,M = list(map(int, input().split())) ab = [] for i in range(M): a,b = list(map(int, input().split())) ab.append((a,b)) ab.sort() ans = 1 l = 1 r = N for a,b in ab: if a < r: l = a r = min(r,b) else: ans += 1 l = a r = b print(ans) ...
p03295
N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(M)] ab.sort(key = lambda x : x[1]) ans = 0 last = -1 for abTemp in ab: if abTemp[0] < last: continue else: ans += 1 last = abTemp[1] print(ans)
N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(M)] ab.sort(key = lambda x : x[1]) ans = 0 last = -1 for a, b in ab: if a < last: continue else: ans += 1 last = b print(ans)
p03295
N, M = list(map(int, input().split())) ab = [tuple(map(int, input().split())) for _ in range(M)] ab.sort(key = lambda x : x[1]) ans = 0 last = -1 for a, b in ab: if a < last: continue else: ans += 1 last = b print(ans)
import sys N, M = list(map(int, input().split())) ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] ab.sort(key = lambda x : x[1]) ans = 0 last = -1 for a, b in ab: if a < last: continue else: ans += 1 last = b print(ans)
p03295
n,m=list(map(int,input().split())) b=[] for i in range(m): b.append(list(map(int,input().split()))) b.sort(key=lambda x:x[1]) time=0 count=0 for k in range(len(b)): if b[k][0]>=time: time=b[k][1] count+=1 print(count)
n,m=list(map(int,input().split())) b=[] for i in range(m): b.append(list(map(int,input().split()))) b.sort(key=lambda x:x[1]) time=0 count=0 for k in range(len(b)): if b[k][0]>=time: time=b[k][1] count+=1 print(count)
p03295
N, M = list(map(int, input().split())) AB = [] for _ in range(M): a, b = list(map(int, input().split())) AB.append((a, b)) import copy import collections fights = AB[:] fights = sorted(fights) bridges = [] for a,b in fights: bridges.append( [x for x in range(a,b)] ) ans...
N, M = list(map(int, input().split())) AB = [] for _ in range(M): a, b = list(map(int, input().split())) AB.append((a, b)) fights = AB[:] fights = sorted(fights, reverse=True) import bisect bridges = [] for a,b in fights: a_position = bisect.bisect(bridges, a) b_position = bisect....
p03295
import heapq N, M =list(map(int, input().split())) p = [] for _ in range(M): A, B= list(map(int, input().split())) n = B - A m = {i for i in range(A, B)} heapq.heappush(p, (n, m)) n = 0 sets = [] for _ in range(M): n, q = heapq.heappop(p) for m, s in sets: if len(s - q...
import sys import itertools input = sys.stdin.readline def read_values(): return list(map(int, input().split())) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for n in range(N)] def main(): N, M = read_values() Q = [read_list() for _ in...
p03295
def main(): n = [int(i) for i in input().split()] bridge = [] counter = 0 reqs = [[int(j) for j in input().split()] for i in range(n[1])] reqs.sort(key=lambda x:(x[0],x[1])) for i in range(1, n[0]+1): if i in bridge: bridge = [] counter += 1 ...
def main(): n = [int(i) for i in input().split()] bridge = set() counter = 0 reqs = [[int(j) for j in input().split()] for i in range(n[1])] reqs.sort(key=lambda x:(x[0],x[1])) preset = 0 for i in range(1, n[0]+1): if i in bridge: bridge.clear() ...
p03295
N, M = list(map(int, input().split())) E = [] for i in range(M): a, b = list(map(int, input().split())) a, b = a-1, b-1 E.append([a, b]) E.sort() l, r = 0, float('inf') ans = 0 for a, b in E: if b <= l or a >= r: ans += 1 l, r = a, b else: l = max(a, l) ...
N, M = list(map(int, input().split())) E = [] for i in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 E.append([a, b]) E.sort(key=lambda x: x[1]) r = 0 ans = 0 for a, b in E: if a >= r: ans += 1 r = b print(ans)
p03295
N, M = list(map(int, input().split())) Requests = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1]) cut, ans = 0, 0 for l, r in Requests: if l >= cut: ans += 1 cut = r print(ans)
N, M = list(map(int, input().split())) Data = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1]) ans, r = 0, 0 for a, b in Data: if a >= r: ans += 1 r = b print(ans)
p03295
n,m = [int(i) for i in input().split()] ab = [] for i in range(m): array = list(map(int,input().split())) ab.append(array) w = [[int(i) for i in range(ab[u][0],ab[u][1])] for u in range(m)] ans = 0 #print(w) import collections while True: d = [e for row in w for e in row] #print(d) if d == []: ...
from operator import itemgetter n, m = [int(i) for i in input().split()] # 区間の終端でソート ab = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1)) # 前回除いた橋 removed = -1 ans = 0 for a in ab: # a が removed より大きい = まだ取り除いてない if a[0] > removed: #print(a) remove...
p03295
import copy N, M = list(map(int, input().split())) reqs = [] for _ in range(M): a, b = list(map(int, input().split())) reqs.append((a, b)) count = 0 while len(reqs) > 0: copied_req = copy.deepcopy(reqs) _, idx = list(map(min, list(zip(*copied_req)))) for req in reqs: if req[0]...
N, M = list(map(int, input().split())) reqs = [] ans = 0 B = 0 for _ in range(M): a, b = list(map(int, input().split())) reqs.append((a, b)) reqs = sorted(reqs, key=lambda x: x[1]) for i in range(M): a, b = reqs[i] if a >= B: B = b ans += 1 print(ans)
p03295
# ABC103D - Islands War from operator import itemgetter as gt def main(): N, M, *AB = list(map(int, open(0).read().split())) Q = sorted([(a, b) for a, b in zip(*[iter(AB)] * 2)], key=gt(1)) ans, cur = 0, -1 for a, b in Q: if not a < cur <= b: ans += 1 cur = b...
# ABC103D - Islands War from operator import itemgetter as gt def main(): N, M, *AB = list(map(int, open(0).read().split())) Q = [(a, b) for a, b in zip(*[iter(AB)] * 2)] Q.sort(key=gt(1)) ans, cur = 0, -1 for a, b in Q: if not a < cur <= b: ans += 1 cur...
p03295
# ABC103D - Islands War from operator import itemgetter as gt def main(): N, M, *AB = list(map(int, open(0).read().split())) Q = [(a, b) for a, b in zip(*[iter(AB)] * 2)] Q.sort(key=gt(1)) ans, cur = 0, -1 for a, b in Q: if not a < cur <= b: ans += 1 cur...
# ABC103D - Islands War from operator import itemgetter as gt def main(): N, M, *AB = list(map(int, open(0).read().split())) Q = [(a, b) for a, b in zip(*[iter(AB)] * 2)] Q.sort(key=gt(1)) ans, cur = 0, -1 for a, b in Q: if a >= cur: # need to break another bridge a...
p03295
N, M = list(map(int, input().split())) war = {} for i in range(M): a, b = list(map(int, input().split())) if(b in war): if(a > war[b]): war[b] = a else: war[b] = a ans = 1 b_list = list(war.keys()) b_list = sorted(b_list) r_bridge = b_list[0] - 1 while(True): ...
N, M = list(map(int, input().split())) war = {} for i in range(M): a, b = list(map(int, input().split())) if(b in war): if(a > war[b]): war[b] = a else: war[b] = a ans = 1 b_list = list(war.keys()) b_list = sorted(b_list) r_bridge = b_list[0] - 1 for b in b_lis...
p03295
from collections import Counter n,m=list(map(int,input().split())) r=[] ac=0 ans=0 def lmax(a): c=[] for i in a: c+=i return Counter(c).most_common()[0][0] for i in range(m): a,b=list(map(int,input().split())) l=list(range(a,b)) r.append(l) c=0 k=0 while ac!=m: ...
n,m=list(map(int,input().split())) r=[] br=[1 for i in range(n)] c=0 for i in range(m): a,b=list(map(int,input().split())) r.append([b,a]) r.sort() for i in range(m): if sum(br[r[i][1]:r[i][0]])==r[i][0]-r[i][1]: br[r[i][0]-1]=0 c+=1 print(c)
p03295
def sarch(listd, num, i): if listd[i - 2] == num: return 1 return 0 N, M = list(map(int, input().split())) data = [] brige = [] for i in range(M): A, B = list(map(int, input().split())) data.append(B) listdata = [0 for j in range(1, A)] for j in range(A, B): listdat...
N, M = list(map(int, input().split())) AB = [] for i in range(M): a, b = list(map(int, input().split())) AB.append([b, a]) AB.sort() for i in range(M): if i == 0: j = AB[i][0] - 1 ans = 1 else: if AB[i][1] <= j and j < AB[i][0]: 1 else: ...
p03295
n,m = list(map(int,input().split())) cut = [] for _ in range(m): a,b = list(map(int,input().split())) cut.append((a,b)) cut.sort() b_min = cut[0][1] count = 0 for a,b in cut[1:]: if b_min > b: b_min = b continue if b_min <= a: count += 1 b_min = b print((count+1))
n,m = list(map(int,input().split())) cut = [] for _ in range(m): a,b = list(map(int,input().split())) cut.append((a,b)) cut.sort(key = lambda x:x[1]) ex_b = cut[0][1] count = 0 for a,b in cut[1:]: if a >= ex_b: count += 1 ex_b = b print((count+1))
p03295
n, m = list(map(int, input().split())) ab_list = list() for _ in range(m): a, b = list(map(int, input().split())) ab_list.append([a, b]) ab_list = sorted(ab_list, key=lambda x: x[1]) n_list = [1 for i in range(n)] for a, b in ab_list: t_list = n_list[a:b] v = t_list.count(0) if v == 0: ...
n, m = list(map(int, input().split())) ab_list = list() for _ in range(m): a, b = list(map(int, input().split())) ab_list.append([a, b]) ab_list = sorted(ab_list, key=lambda x: x[1]) x = -1 ans = 0 for a, b in ab_list: if a <= x: continue else: x = b-1 ans += 1 prin...
p03295
n,m=list(map(int,input().split())) l_target=[] for _ in range(m): a,b=list(map(int,input().split())) l_target.append((a,b)) l_target.sort(key=lambda x:x[1]) #print(l_target) cut_pos=[] for target in l_target: is_ok=False for pos in cut_pos: if (target[0]<pos<target[1]): ...
n,m=list(map(int,input().split())) l_target=[] for _ in range(m): a,b=list(map(int,input().split())) l_target.append((a,b)) l_target.sort(key=lambda x:x[1]) count=0 pre_pos=0 for target in l_target: if (target[0]<pre_pos<target[1]): continue count+=1 pre_pos=target[1]...
p03295
n, m = list(map(int, input().split())) ab = [[int(i) for i in input().split()] for i in range(m)] count = 0 for i in range(m): ab[i].sort() while len(ab) > 0: ab = sorted(ab, key = lambda x: x[1]) end = ab[0] list.sort(ab, reverse=True) remove = ab.index(end) if remove >= 1: w...
n, m = list(map(int, input().split())) l = [] for i in range(m): a, b = list(map(int, input().split())) l.append((b, a)) l.sort() answer = 0 last = 0 for b, a in l: if a >= last: answer += 1 last = b print(answer)
p03295
import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) data = [list(map(int, input().split())) for _ in range(m)] rule = [[] for _ in range(n)] for i in range(m): rule[data[i][0] - 1].append(data[i][1]) rule[data[i][1] - 1].append(data[i][0]) ...
import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) data = [list(map(int, input().split())) for _ in range(m)] rule = [[] for _ in range(n)] for i in range(m): rule[data[i][0] - 1].append(data[i][1]) rule[data[i][1] - 1].append(data[i][0])...
p03295
N,M=list(map(int,input().split())) conflict=[tuple(map(int,input().split())) for i in range(M)] conflict.sort(key=lambda x:x[0]) ans=0 Right=N for i in range(M): if conflict[i][0]>=Right: Right=conflict[i][1] ans+=1 else: Right=min(Right,conflict[i][1]) print((ans+1))
N,M=list(map(int,input().split())) need=[tuple(map(int,input().split())) for i in range(M)] need.sort(key=lambda x:x[0]) ans=0 bef=0 for a,b in need: if a<=bef: bef=min(b-1,bef) else: ans+=1 bef=b-1 print(ans)
p03295
N,M=list(map(int,input().split())) need=[tuple(map(int,input().split())) for i in range(M)] need.sort(key=lambda x:x[0]) ans=0 bef=0 for a,b in need: if a<=bef: bef=min(b-1,bef) else: ans+=1 bef=b-1 print(ans)
N,M=list(map(int,input().split())) need=[tuple(map(int,input().split())) for i in range(M)] ans=0 need.sort(key=lambda x:x[1]) bef=1 for a,b in need: if a<bef: continue else: ans+=1 bef=b print(ans)
p03295
n,m = list(map(int,input().split())) demands= [] for i in range(m): demands.append(list(map(int,input().split()))) demands.sort() cut = [] for d in demands: flag = True for c in cut: if c[0] < d[1] and c[1] > d[0]: flag = False c[0] = max(c[0],d[0]) ...
N,M=list(map(int,input().split())) d = [list(map(int,input().split())) for _ in range(M)] d.sort(key=lambda x:x[1]) ans=0 c=0 for i in range(M): a,b=d[i] if a>=c: ans+=1 c=b print(ans)
p03295
n, m = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(m)] x = 0 ans = 0 while x < n: p = 10000000 for y in a: if y[0] >= x: p = min(p, y[1]) for y in a: if y[0] < x: a.remove(y) if p <= n: ans += 1 ...
n, m = list(map(int, input().split())) l = [] for i in range(m): a, b = list(map(int, input().split())) l.append([b, a]) l.sort() ans = 0 x = 0 for i in range(m): if l[i][1] >= x: ans += 1 x = l[i][0] print(ans)
p03295
from operator import itemgetter n,m = list(map(int, input().split())) ab = [] for i in range(m): a,b = list(map(int, input().split())) ab.append([a-1,b-1]) ab.sort(key=itemgetter(1)) fall = [0 for i in range(n-1)] for i in range(len(ab)): flag = True for j in range(ab[i][0],ab[i][1])...
from operator import itemgetter n,m = list(map(int, input().split())) ab = [] for i in range(m): a,b = list(map(int, input().split())) ab.append([a-1,b-1]) ab.sort(key=itemgetter(1)) fall = -1 ans = 0 for i in range(m): if fall < ab[i][0]: ans += 1 fall = ab[i][1]-1 ...
p03295
N, M = list(map(int, input().split())) war_pairs = [] for _ in range(M): a, b = list(map(int, input().split())) war_pairs.append((a, b)) # 取り除く橋についてbit全探索 bridge_cnt = N - 1 for i in range(2 ** bridge_cnt): bridges = [True] * bridge_cnt for j in range(bridge_cnt): if (i >> j) & 1: ...
N, M = list(map(int, input().split())) pairs = [] for _ in range(M): i, j = list(map(int, input().split())) pairs.append([i, j]) pairs.sort(key=lambda x: x[1]) # 終端が早い順に並び替え # 重複区間除去(greedy) current = 0 bag = [] for pair in pairs: if pair[0] >= current: bag.append(pair) curr...
p03295
N, M = list(map(int, input().split())) dem = [[0, 0] for i in range(M)] for i in range(M): dem[i][0], dem[i][1] = list(map(int, input().split())) dem.sort(key=lambda x: (x[1])) br_flag = [False for i in range(N-1)] count = 0 for i in range(M): for j in range(dem[i][1]-dem[i][0]): if br_flag[dem...
N, M = list(map(int, input().split())) dem = [[0, 0] for i in range(M)] for i in range(M): dem[i][0], dem[i][1] = list(map(int, input().split())) dem.sort(key=lambda x: (x[1])) br_flag = [False for i in range(N-1)] count = 0 a = 0 for i in range(M): if a < dem[i][0]: br_flag[dem[i][1]-2] = Tru...
p03295
N, M, *A = list(map(int, open(0).read().split())) *A, = list(zip(*[iter(A)]*2)) A.sort() cnt = 0 R = 0 for a, b in A: if R <= a: cnt += 1 R = b elif b < R: R = b print(cnt)
N,M,*A=list(map(int,open(0).read().split()));c=0 for a,b in sorted(zip(*[iter(A)]*2))[::-1]: if b<=N:c+=1;N=a print(c)
p03295
N, M = [int(t) for t in input().split()] R = [] for i in range(M): a, b = [int(t) for t in input().split()] R.append((a, b)) R.sort() inf = float('inf') Ra = [inf for a in range(N + 1)] for a, b in R: Ra[a] = min(Ra[a], b) R = [(a, Ra[a]) for a in range(1, N+1) if Ra[a] != inf] R.sort(key=l...
N, M = [int(t) for t in input().split()] R = [] for i in range(M): a, b = [int(t) for t in input().split()] R.append((a, b)) R.sort(key=lambda r: r[1]) last = -1 count = 0 for a, b in R: if last < a: last = b - 1 count += 1 print(count)
p03295
N, M = [int(t) for t in input().split()] R = [] for i in range(M): a, b = [int(t) for t in input().split()] R.append((a, b)) R.sort(key=lambda r: r[1]) last = -1 count = 0 for a, b in R: if last < a: last = b - 1 count += 1 print(count)
N, M = [int(t) for t in input().split()] R = [] for i in range(M): a, b = [int(t) for t in input().split()] R.append((a, b)) last = -1 # the last broken bridge count = 0 # the number of broken bridges for a, b in sorted(R, key=lambda r: r[1]): if last < a: last = b - 1 count ...
p03295
n,m=list(map(int,input().split())) ab=[list(map(int,input().split()))for _ in range(m)] ab.sort() l,r=ab[0] ans=1 for i,j in ab[1:]: if j<=l or r<=i: ans+=1 l,r=i,j l=max(l,i) r=min(r,j) print(ans)
n,m=list(map(int,input().split())) ab=[list(map(int,input().split()))for _ in range(m)] ab.sort() l,r=ab[0] ans=1 for a,b in ab[1:]: if r<=a: ans+=1 l,r=a,b else: l=max(l,a) r=min(r,b) print(ans)
p03295
from pprint import pprint from copy import deepcopy #N <= 10**5なので、全探索はNG #Greedyでいける? n,m = list(map(int,input().split())) requests = [list(map(int,input().split())) for _ in range(m)] bridge_list = [[] for _ in range(n-1)] for i in range(m): startpoint = requests[i][0] endpoint = requests...
#この方法だとTLEになるためNG from pprint import pprint from copy import deepcopy #N <= 10**5なので、全探索はNG #Greedyでいける? n,m = list(map(int,input().split())) requests = [list(map(int,input().split())) for _ in range(m)] #区間スケジュール問題と考え、終端が小さい順で並べる。その後Greedyで計算。 requests = sorted(requests, key=lambda x:x[1]) count...
p03295
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] AB.sort(key = lambda x: x[0]) MAX = 10 ** 9 count = 1 min_ = MAX for a, b in AB: if a < min_: min_ = min(min_, b) else: count += 1 min_ = b print (count)
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key = lambda x: x[0]) count = 1 B = 10 ** 9 for a, b in AB: if a < B: B = min(B, b) else: count += 1 B = b print (count)
p03295
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key = lambda x: x[0]) count = 1 B = 10 ** 9 for a, b in AB: if a < B: B = min(B, b) else: count += 1 B = b print (count)
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key = lambda x: x[1]) #右側が小さい順にソート AB.sort(key = lambda x: x[0]) #左側が小さい順にソート ans = 0 right = N + 1 for a, b...
p03295
from operator import itemgetter n, m = [int(i) for i in input().split()] A, B = list(zip(*[[int(i) for i in input().split()] for j in range(m)])) A, B = list(zip(*sorted(zip(A, B), key=itemgetter(1, 0)))) last = -1 ans = 0 for a, b in zip(A, B): if last <= a: ans += 1 last = b pr...
n, m = [int(i) for i in input().split()] A = [[int(i) for i in input().split()] for j in range(m)] A.sort(key=lambda a:a[1]) ans = 0 i = 0 while i < m: b = A[i][1] ans += 1 i += 1 while i < m: if A[i][0] >= b: break i += 1 print(ans)
p03295
N,M = list(map(int,input().split())) L = [list(map(int,input().split())) for i in range(M)] L.sort() ans = 1 l = L[0][0] r = L[0][1] for a,b in L: if r <= a or l >= b: ans += 1 l = a r = b else: l = a r = min(r,b) print(ans)
N,M = list(map(int,input().split())) L = [list(map(int,input().split())) for i in range(M)] L.sort() ans = 1 l = L[0][0] r = L[0][1] for a,b in L: if r <= a: ans += 1 l = a r = b else: l = a r = min(r,b) print(ans)
p03295
N,M = list(map(int,input().split())) L = [list(map(int,input().split())) for i in range(M)] L.sort() ans = 1 l = L[0][0] r = L[0][1] for a,b in L: if r <= a: ans += 1 l = a r = b else: l = a r = min(r,b) print(ans)
N,M = list(map(int,input().split())) L = [list(map(int,input().split())) for i in range(M)] L.sort() ans = 0 l,r = 0,0 for a,b in L: l = a if r <= a: ans += 1 r = b else: r = min(r,b) print(ans)
p03295
N,M = list(map(int,input().split())) L = [list(map(int,input().split())) for i in range(M)] L.sort() ans = 0 l,r = 0,0 for a,b in L: l = a if r <= a: ans += 1 r = b else: r = min(r,b) print(ans)
N,M = list(map(int,input().split())) L = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:x[1]) p,res = 0,0 for a,b in L: if a > p: p = b-1 res += 1 print(res)
p03295
N,M = list(map(int, input().split())) table = [] ans = 1 for i in range(M): a,b = list(map(int,input().split())) table.append((a,b)) table.sort() r = N for a,b in table: if r <= a: ans += 1 r = N r = min(b,r) print(ans)
N,M = list(map(int,input().split())) table = [] for i in range(M): a,b = list(map(int,input().split())) a -= 1 b -= 1 table.append((a,b)) table = sorted(table,key=lambda x:x[1]) cur_r = table[0][1] ans = 1 for i in range(1,M): l,r = table[i] if cur_r <= l: ans += 1 ...
p03295
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
p03295
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemge...
p03295
N, M = [int(t) for t in input().split()] a = [[0]*2 for i in range(M)] # 始点と距離 for i in range(M): s, e = [int(t) for t in input().split()] a[i][0] = s - 1 a[i][1] = e - 1 b = sorted(a, key=lambda x: x[1]) count = 1 flag = b[0][1] for i in range(1, M): if b[i][0] < flag: continue ...
N, M = [int(t) for t in input().split()] a = [[0]*2 for i in range(M)] for i in range(M): a[i][0], a[i][1] = [int(t) for t in input().split()] b = sorted(a, key=lambda x: x[1]) count = 1 flag = b[0][1] for i in range(1, M): if b[i][0] < flag: continue elif b[i][1] > flag: flag...
p03295
N, M = list(map(int, input().split())) kukan = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1]) ans = 0 while kukan: cut = kukan[0][1] - 1 kukan = list([x for x in kukan if not x[0] <= cut < x[1]]) ans += 1 print(ans)
def main(): N, M = list(map(int, input().split())) kukan_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1]) ans = 0 cut = 0 for kukan in kukan_list: if cut >= kukan[0]: continue ans += 1 cut = kukan[1] - 1 ...
p03295
n , m = list(map(int, input().split())) # ab = [list(map(int, input().split())) for _ in range(m)] ranges = [[] for _ in range(m)] for i in range(m): a,b = list(map(int,input().split())) ranges[i] = [a,b] ranges = sorted(ranges, key = lambda x:x[1]) MAX = - float("inf") ans = 0 for i in range(m): ...
n , m = list(map(int, input().split())) # ab = [list(map(int, input().split())) for _ in range(m)] ranges = [[] for _ in range(m)] for i in range(m): a,b = list(map(int,input().split())) ranges[i] = [a,b] ranges = sorted(ranges, key = lambda x:x[1]) MAX = - float("inf") ans = 0 for i in range(m): ...
p03295
N, M = list(map(int, input().split())) ab_s = [list(map(int, input().split())) for _ in range(M)] bridges = [0] * N ab_s = sorted(ab_s, key=lambda x: x[1]) for ab in ab_s: if sum(bridges[ab[0]:ab[1]]) == 0: bridges[ab[1]-1] = 1 print((sum(bridges)))
N, M = list(map(int, input().split())) ab_s = [list(map(int, input().split())) for _ in range(M)] bridges = [0] * N ab_s = sorted(ab_s, key=lambda x: x[1]) for ab in ab_s: if bridges[ab[1]-1] - bridges[ab[0]-1] == 0: for i in range(ab[1]-1, N): bridges[i] += 1 print((bridges[-1]))
p03295
def g(l, n, v): for i in n: for j in range(i[0], i[1]): l[j] += v def f(n, m, A): global D max_n = max(enumerate(D[n:m], n), key=lambda x:x[1])[0] dA = {i for i in A if i[0] <= max_n < i[1]} g(D, dA, -1) return max_n, A - dA def ff(n, m, A): i, A_ = f(n, m,...
w = [int(i) for i in input().split()] N = w[0] M = w[1] A = {tuple([int(j) for j in input().split()]) for i in range(M)} A_ = sorted(A, key=lambda x: x[1]) bridge = 0 c = 0 for i in A_: if i[0] > bridge: bridge = i[1]-1 c += 1 print(c)
p03295
def main(): N, M = (int(i) for i in input().split()) ab = [tuple(int(i) for i in input().split()) for _ in range(M)] ab.sort(key=lambda p: p[1]) pre_b = 1 ans = 0 for a, b in ab: if pre_b <= a: ans += 1 pre_b = b print(ans) if __name__ == '__m...
def main(): import sys input = sys.stdin.buffer.readline N, M = (int(i) for i in input().split()) AB = [[int(i) for i in input().split()] for j in range(M)] AB.sort(key=lambda p: p[1]) mx_b = AB[0][1] ans = 1 for a, b in AB[1:]: if a < mx_b: continue ...
p03295
from operator import itemgetter n,m=list(map(int, input().split())) A=[] B=[] a=0 b=0 for i in range(m): a,b=list(map(int, input().split())) A.append([a,b]) A.sort(key=itemgetter(1)) bri=[1 for i in range(n)] #bri[0]は1,2番目の島をつなぐ count=0 for i in range(m): a=A[i][0] b=A[i][1] if n...
from operator import itemgetter n,m=list(map(int, input().split())) A=[] B=[] a=0 b=0 for i in range(m): a,b=list(map(int, input().split())) A.append([a,b]) A.sort(key=itemgetter(1)) bri=0 #取った橋のうち番号最大の島のもの。bri=5なら4,5番目の島の橋 count=0 for i in range(m): a=A[i][0] b=A[i][1] if a>=bri...
p03295
def ck(a,b,arr): if sum(arr[a:b]) == b - a: return 1 else: return 0 N,M=list(map(int,input().split())) List=[list(map(int,input().split())) for i in range(M)] List_2 = [0] * M arr = [1] * N for i in range(M): a = List[i][1] b = List[i][0] List_2[i] = [a,b] List_2.sort() for i...
def ck(a,b,arr): if arr >= a and arr < b: return 0 else: return 1 N,M=list(map(int,input().split())) List=[list(map(int,input().split())) for i in range(M)] List_2 = [0] * M arr = 0 cnt = 0 for i in range(M): a = List[i][1] b = List[i][0] List_2[i] = [a,b] List_2.sort() for ...
p03295
if __name__ == '__main__': islands_count, demands_count = list(map(int, input().split())) demands = [] bridges = [True for _ in range(islands_count - 1)] for i in range(demands_count): demand = list(map(int, input().split())) demands.append(demand) demands.sort(key=lambda x: x[1]) for demand in ...
if __name__ == '__main__': islands_count, demands_count = list(map(int, input().split())) demands = [] break_count = 0 for i in range(demands_count): demand = list(map(int, input().split())) demands.append(demand) demands.sort(key=lambda x: x[1]) west_edge = 0 ...
p03295
n, m = list(map(int, input().split())) ab = [] for i in range(m): a, b = list(map(int, input().split())) ab.append((a - 1, 2, i)) ab.append((b - 1, 1, i)) ab.sort() ans = 0 separated = [False] * m buf = set() for island, ab, i in ab: if ab == 1: if separated[i]: contin...
n, m = list(map(int, input().split())) disputes = [] for i in range(m): a, b = list(map(int, input().split())) disputes.append((b, a)) disputes.sort() ans = 0 most_right_bridge = 0 for b, a in disputes: if most_right_bridge <= a: ans += 1 most_right_bridge = b print(ans)
p03295
from collections import defaultdict n, m = list(map(int, input().split())) disputes = defaultdict(int) for i in range(m): a, b = list(map(int, input().split())) disputes[b] = max(disputes[b], a) ans = 0 most_right_bridge = 0 for b in sorted(disputes.keys()): if most_right_bridge <= disputes[b]: ...
import sys from collections import defaultdict n, m = list(map(int, input().split())) disputes = defaultdict(int) for line in sys.stdin.readlines(): a, b = list(map(int, line.split())) if disputes[b] < a: disputes[b] = a ans = 0 most_right_bridge = 0 for b in sorted(disputes.keys()): if...
p03295
N,M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(M)] AB.sort() ans=0 while AB: a=AB[-1][0] AB=list([x for x in AB if x[1]<=a]) ans+=1 print(ans)
N,M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(M)] AB.sort() ar=N+1 ans=0 for i in reversed(list(range(M))): a,b=AB[i] if b<=ar: ans+=1 ar=a print(ans)
p03295
# Segment tree class SegmentTree(): _data = [] _offset = 0 _size = 0 def __init__(self, size): _size = size t = 1 while t < size: t *= 2 self._offset = t - 1 self._data = [0 for _ in range(t * 2 - 1)] def update(self, index, value):...
N, M = list(map(int, input().split())) ab = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, input().split())) ab[a].append(b) dp = [0] * (N + 1) for i in range(1, N + 1): dp[i] = max(dp[i], dp[i - 1]) for j in ab[i]: dp[j] = max(dp[j], dp[i] + 1) print((dp[N]))...
p03295
from sys import stdin readline = stdin.readline N, M = list(map(int, readline().split())) ab = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, readline().split())) ab[a].append(b) dp = [0] * (N + 1) for i in range(1, N + 1): dp[i] = max(dp[i], dp[i - 1]) for j in ab[i]...
from sys import stdin readline = stdin.readline N, M = list(map(int, readline().split())) ab = [list(map(int, readline().split())) for _ in range(M)] ab.sort(key=lambda x: x[1]) result = 0 t = -1 for a, b in ab: a, b = a - 1, b - 1 if a <= t < b: continue result += 1 t = b - 1 ...
p03295
# Segment tree (Sum) class SegmentTree(): _data = [] _offset = 0 _size = 0 def __init__(self, size): _size = size t = 1 while t < size: t *= 2 self._offset = t - 1 self._data = [0 for _ in range(t * 2 - 1)] def update(self, index, v...
from sys import stdin readline = stdin.readline N, M = list(map(int, readline().split())) ab = [[] for _ in range(N + 1)] for _ in range(M): a, b = list(map(int, readline().split())) ab[a].append(b) dp = [0] * (N + 1) for i in range(1, N + 1): dp[i] = max(dp[i], dp[i - 1]) for j in ab[i]...
p03295
# Segment tree (+) class SegmentTree: _f = None _data = None _offset = None _size = None def __init__(self, size, f): self._f = f self._size = size t = 1 while t < size: t *= 2 self._offset = t - 1 self._data = [0] * (t * 2 -...
# Segment tree (+) from operator import add from sys import stdin class SegmentTree: _f = None _data = None _offset = None _size = None def __init__(self, size, f): self._f = f self._size = size t = 1 while t < size: t *= 2 self...
p03295
def main(): N, M = list(map(int, input().split())) ab = [[int(i) for i in input().split()] for _ in range(M)] ab = sorted(ab, key=lambda x: x[1]) bd = ['0'] * (N - 1) for a, b in ab: if bd[a-1:b-1].count('1') == 0: bd[b - 2] = '1' print((bd.count('1'))) main()
def main(): N, M = list(map(int, input().split())) ab = [[int(i) for i in input().split()] for _ in range(M)] ab = sorted(ab, key=lambda x: x[1]) last = ab[0][1] - 1 ans = 1 for a, b in ab[1:]: if last >= a: continue ans += 1 last = b - 1 print(...
p03295
def log(s): # print("| " + str(s), file=sys.stderr) pass def output(x): print(x, flush=True) def input_ints(): return map(int, input().split()) def main(): num_nodes, num_regions = tuple(input_ints()) regions = [tuple(input_ints()) for _ in range(num_regions)] nodes =...
def log(s): # print("| " + str(s), file=sys.stderr) pass def output(x): print(x, flush=True) def input_ints(): return map(int, input().split()) def main(): num_nodes, num_regions = tuple(input_ints()) regions = [tuple(input_ints()) for _ in range(num_regions)] regions.s...
p03295
# ABC103D # 貪欲法:区間スケジューリング問題に帰着 # ソートして喧嘩している遠い島(b[i])の最も近いところから貪欲に選んでいく # ex) 1-10, 2-5, 6-8 # なら2-5, 6-8を選ぶ. N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(M)] ab.sort(key=lambda x: x[1]) ##print(ab) ans = 1 # 一つ目分 tmp = ab[0][1] - 0.1 # 一つ目の橋は必ず...
N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(M)] ab.sort(key=lambda x: x[1]) ans = 1 tmp = ab[0][1] for i in range(1, M): if tmp <= ab[i][0]: ans += 1 tmp = ab[i][1] print(ans)
p03295
import sys from collections import defaultdict input = sys.stdin.readline n, m = list(map(int, input().split())) path = defaultdict(list) for _ in range(m): a, b = list(map(int, input().split())) path[a].append(b) idx = 1 ans = 1 right = n while idx <= n: candidate = path[idx] if no...
import sys input = sys.stdin.readline INF = float('INF') n, m = list(map(int, input().split())) path = [INF]*(n+1) for _ in range(m): a, b = list(map(int, input().split())) path[a] = min(path[a], b) left = 1 ans = 1 right = n while left <= n: cut = path[left] if cut == INF: l...
p03295
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] cnt = 0 while len(AB) > 0: bridges = [0] * (N - 1) for a, b in AB: for i in range(a - 1, b - 1): bridges[i] += 1 collapse = bridges.index(max(bridges)) cnt += 1 AB = list(...
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key=lambda ab: ab[1]) removed = list() for a, b in AB: if len(removed) == 0: removed.append(b - 1) elif a <= removed[-1] < b: continue else: removed.append(b - 1) pri...
p03295
#!/usr/bin/env python3 from collections import defaultdict def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = defaultdict(list) btoi = defaultdict(list) for i in range(m): aa, bb = list(map(int, input().split())) a.append(aa - 1) b.appe...
#!/usr/bin/env python3 import sys from collections import defaultdict def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = defaultdict(list) btoi = defaultdict(list) for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.appen...
p03295
#!/usr/bin/env python3 import sys from collections import defaultdict def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = defaultdict(list) btoi = defaultdict(list) for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.appen...
#!/usr/bin/env python3 import sys def main(): n, m = list(map(int, input().split())) a = [] b = [] atoi = [[] for i in range(n)] btoi = [[] for i in range(n)] for i in range(m): aa, bb = list(map(int, sys.stdin.readline().split())) a.append(aa - 1) b.append...
p03295
N, M = list(map(int, input().split())) requests = [tuple(map(int, input().split())) for _ in range(M)] requests.sort(key=lambda x: x[1]) connects = [1] * N for a, b in requests: if all(connects[a:b]): connects[b-1] = 0 print((connects.count(0)))
N, M = list(map(int, input().split())) requests = [tuple(map(int, input().split())) for _ in range(M)] requests.sort(key=lambda x: x[1]) counts = 0 left = 0 for a, b in requests: if a >= left: left = b counts += 1 print(counts)
p03295
from heapq import heappush, heappop N, M = list(map(int, input().split())) LR = [tuple(map(int, input().split())) for _ in range(M)] LR.sort(key=lambda a: (a[0], -a[0])) R = 10**18 ans = 0 for l, r in LR: if R <= l: ans += 1 R = 10**18 R = min(R, r) print((ans + 1))
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key=lambda a: (a[0], -a[1])) ans = 1 right = 10**18 for l, r in AB: if l >= right: ans += 1 right = 10**18 right = min(right, r) print(ans)
p03295
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key=lambda a: (a[0], -a[1])) ans = 1 right = 10**18 for l, r in AB: if l >= right: ans += 1 right = 10**18 right = min(right, r) print(ans)
N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(M)] AB.sort(key=lambda a: (a[1], a[0])) mx = 10**18 ans = 0 for a, b in AB: if a >= mx: ans += 1 mx = 10**18 mx = min(mx, b) print((ans + 1))
p03295
N, M = list(map(int,input().split())) banned_list = [] for i in range(M): banned_list.append(tuple(map(int,input().split()))) banned_list = sorted(banned_list,key=lambda x:x[1]) status = [1 for _ in range(N-1)] counter = 0 for i in range(M): a = banned_list[i][0] b = banned_list[i][1] if n...
N, M = list(map(int,input().split())) banned_list = [] for i in range(M): banned_list.append(tuple(map(int,input().split()))) banned_list = sorted(banned_list,key=lambda x:x[1]) #status = [1 for _ in range(N-1)] status = set() counter = 0 for i in range(M): a = banned_list[i][0] b = banned_list[...
p03295
def main(): N, M = list(map(int, input().split())) a_b = sorted([list(map(int, input().split())) for _ in range(M)]) used = [0] * M ans = 0 for i in range(M): k = M - i - 1 if used[k]: continue used[k], c = 1, a_b[k][0] for j in range(k): ...
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) a_b = sorted([list(map(int, input().split())) for _ in range(M)]) used = [0] * M ans = 0 for i in range(M): k = M - i - 1 if used[k]: continue used[k], c = 1, a_b...
p03295
N, M = list(map(int, input().split())) bridges = [] for i in range(M): bridges.append(list(map(int, input().split()))) intervals = sorted(bridges, key=lambda x: (x[1], x[0])) #print(bridges) count=1 done=[intervals[0]] for interval in intervals: #print(interval) if not interval[0] < done[-1][1]: ...
N, M = list(map(int, input().split())) bridges = [] for i in range(M): bridges.append(list(map(int, input().split()))) intervals = sorted(bridges, key=lambda x: x[1]) #print(bridges) count=1 done=[intervals[0]] for interval in intervals: #print(interval) # we cut the last bridage of last process...
p03295
N,M = list(map(int,input().split(' '))) sections_a = [] sections_b = [] for _ in range(M): a,b = list(map(int,input().split(' '))) sections_a.append(a) sections_b.append(b) tmp_a = [sections_a[0]] tmp_b = [sections_b[0]] for i in range(1,len(sections_a)): for j in range(i): if sec...
N,M = list(map(int,input().split(' '))) sections = [list(map(int,input().split(' '))) for _ in range(M) ] ''' tmp_list = [sections[0]] for i in range(1,len(sections)): for j in range(i): if sections[i] < tmp_list[j]: tmp_list.insert(j,sections[i]) break if j == i -...
p03295
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right ...
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right ...
p03295
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right ...
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right ...
p03295
a,b = list(map(int,input().split())) input_lines = [list(map(int,input().split())) for i in range(b)] input_lines = sorted(input_lines,key=lambda x: x[1]) #各要素において[1]に基づきソートする c=[0] for i in input_lines: p=0 for j in c: if j > i[0]: p=1 if p==0: c.append(i[1]) ...
a,b = list(map(int,input().split())) input_lines = [list(map(int,input().split())) for i in range(b)] input_lines = sorted(input_lines,key=lambda x: x[1]) #各要素において[1]に基づきソートする c=[0] for i in input_lines: #for j in c: # if j > i[0]: # p=1 if max(c)<=i[0]: c.append(i[1]) ...
p03295
N, M = list(map(int, input().split())) _input = [] for i in range(M): _input.append(list(map(int,input().split()))) _input.sort(key=lambda x: x[1]) removed = [] for a,b in _input: flag = False for i in removed: if a <= i < b: flag = True if not flag: removed...
N, M = list(map(int, input().split())) _input = [] for i in range(M): _input.append(list(map(int,input().split()))) _input.sort(key=lambda x: x[1]) removed = [] for a,b in _input: flag = False for i in removed: if a <= i < b: flag = True break if not fla...
p03295
n,m = list(map(int,input().split())) youbou = [list(map(int,input().split())) for i in range(m)] youbou.sort(key = lambda x: x[1]) ans,prev = 0,-1 for p in youbou: if prev < p[0]: prev = p[1] - 1 ans += 1 print(ans)
n,m = list(map(int,input().split())) youbou = [list(map(int,input().split())) for i in range(m)] youbou.sort(key = lambda x: x[1]) ans,prev = 0,-1 for i in range(m): if prev < youbou[i][0]: prev = youbou[i][1] - 1 ans += 1 print(ans)
p03295
N,M=list(map(int,input().split())) request=[] for _ in range(M): request.append(list(map(int,input().split()))) request.sort(key=lambda x: x[0]) memory=request[0][1] head = request[0][0] index = 0 ans = 0 def equal(): if index == M-1: return False else: return head == request[index+1][0] ...
N,M=list(map(int,input().split())) AB=[] for _ in range(M): AB.append(tuple(map(int,input().split()))) request_max=0 request_num=0 AB.sort(key=lambda x:x[1]) for (a,b) in AB: if a>=request_max: request_num +=1 request_max = b print(request_num)
p03295
import sys input = sys.stdin.readline n,m=list(map(int,input().split())) l=[[0,0] for _ in range(m)] for i in range(m): l[i][1],l[i][0]=list(map(int,input().split())) l=sorted(l) ans=1 for _ in range(n-1): for i in l[1:]: if i[1]<l[0][0]: l.remove(i) l.remove(l[0]) i...
import sys input = sys.stdin.readline n,m=list(map(int,input().split())) l=[[0,0] for _ in range(m)] for i in range(m): l[i][1],l[i][0]=list(map(int,input().split())) l=sorted(l) ans=1 c=l[0][0] for i in range(m): if l[i][1]>=c: ans+=1 c=l[i][0] else: continue pr...
p03295
N,M=list(map(int,input().split())) bridges = [1]*N islandswar = [[] for _ in range(N+1)] for i in range(M): a,b = list(map(int,input().split())) islandswar[b].append(a) count = 0 def check(a,b): for i in range(a,b): if bridges[i] == 0: return False return True f...
N,M=list(map(int,input().split())) bridges = [1]*N islandswar = [[] for _ in range(N+1)] for i in range(M): a,b = list(map(int,input().split())) islandswar[b].append(a) count = 0 currightest = 0 def check(a,b): for i in range(a,b): if bridges[i] == 0: return False retur...
p03295
#!/usr/bin/env python3 import sys import operator def solve(N: int, M: int, a: "List[int]", b: "List[int]"): AB = list(zip(a,b)) AB.sort(key=operator.itemgetter(1)) db = [] for a,b in AB: bAppend = True for i in range(a,b): if i in db: bAppe...
#!/usr/bin/env python3 import sys import operator def solve(N: int, M: int, a: "List[int]", b: "List[int]"): AB = list(zip(a,b)) AB.sort(key=operator.itemgetter(1)) db = [] for a,b in AB: bAppend = True for di in db: if a <= di < b: bAppend ...
p03295
import sys read = sys.stdin.buffer.read input = sys.stdin.readline input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(eval(input())) def MI(): return list(map(int,input().split())) def MF(): return list(m...
import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(eval(input())) def MI(): return list(map(int,input().split())) def MF(): return list(map(float,input().split())) def LI(): return list(map(int,...
p03295
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x:x[1]) B = 0 ans = 0 for i in range(M): a, b = ab[i] if a >= B: B = b ans += 1 ...
import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1]) ans = 0 pre = -1 for a, b in ab: if a >= pre: ans += 1 pre = b print(an...
p03295
n, m = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1]) remove = ab[0][1] res = 1 for i in range(m): if remove <= ab[i][0]: res += 1 remove = ab[i][1] print(res)
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) AB = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x:x[1]) res = 0 remove = -1 for a, b in AB: ...
p03295
break_offs = set() N, M = list(map(int, input().split())) for i in range(M): a, b = list(map(int, input().split())) if a > b: a, b = b, a break_offs.add((a, b)) covered = [] break_offs = sorted(list(break_offs), key=lambda x:x[1]) for a, b in break_offs: found = False for area i...
break_offs = set() N, M = list(map(int, input().split())) for i in range(M): a, b = list(map(int, input().split())) if a > b: a, b = b, a break_offs.add((a, b)) last_bridge = 0 count = 0 for a, b in sorted(list(break_offs), key=lambda x:x[1]): if last_bridge <= a: last_bridg...
p03295
from copy import copy from collections import deque N,M=list(map(int,input().split())) ab=[] for i in range(M): a,b=list(map(int,input().split())) ab.append([a,b]) """ N=10**5 M=10**5 ab=[] for i in range(1,N): ab.append([i,i+1]) """ AB=copy(ab) ab.sort(key=lambda x :x[1]) AB.sort() ab=...
from collections import deque N,M=list(map(int,input().split())) ab=[] for i in range(M): a,b=list(map(int,input().split())) ab.append([a,b]) ab.sort(key=lambda x :x[1]) ans=deque() for i in ab: if len(ans)>0: if i[0]<ans[-1] : continue ans.append(i[1]) print((len(ans)...
p03295
from collections import deque N,M=list(map(int,input().split())) ab=[] for i in range(M): a,b=list(map(int,input().split())) ab.append([a,b]) ab.sort(key=lambda x :x[1]) ans=deque() for i in ab: if len(ans)>0: if i[0]<ans[-1] : continue ans.append(i[1]) print((len(ans)...
N,M=list(map(int,input().split())) ab=[] for i in range(M): a,b=list(map(int,input().split())) a,b=a-1,b-2 ab.append([a,b]) ab.sort(key=lambda x:x[1]) ans=1 x=ab[0][1] for a,b in ab[1:]: if a<=x: continue x=b ans+=1 print(ans)
p03295