input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
# N個のimosなので二次元でやる 0.5がうざいので*2する( (2*10^5) * C ) # なぜか2WAが取れない # 嘘解法? N, C = list(map(int, input().split())) x = 2 * (10**5) # x = 30 # test imos = [[0 for _ in range(x)] for _ in range(C)] for _ in range(N): s, t, c = list(map(int, input().split())) s, t, c = s * 2 - 1, t * 2 - 1, c - 1 imos[c][s - 1] += 1 imos[c][t] -= 1 for i in range(C): for j in range(1, x): imos[i][j] += imos[i][j - 1] imos[i][j] = min(1, imos[i][j]) # test ans = 0 for j in range(x): tmp = 0 for i in range(C): tmp += imos[i][j] ans = max(ans, tmp) # print("-----------") # for x in imos: # print(x) print(ans) # 1 3 # 3 4 2
# N個のimosなので二次元でやる 0.5がうざいので*2する( (2*10^5) * C ) # なぜか2WAが取れない # これ嘘解法ぽい気がする N, C = list(map(int, input().split())) x = 2 * (10**5) # x = 30 # test imos = [[0 for _ in range(x)] for _ in range(C)] for _ in range(N): s, t, c = list(map(int, input().split())) s, t, c = s * 2 - 1, t * 2 - 1, c - 1 imos[c][s - 1] += 1 imos[c][t] -= 1 # imos[c][s - 1] = min(1, imos[c][s - 1]) # test for i in range(C): for j in range(1, x): imos[i][j] += imos[i][j - 1] # imos[i][j] = min(1, imos[i][j]) # test ans = 0 for j in range(x): tmp = 0 for i in range(C): tmp += min(1, imos[i][j]) ans = max(ans, tmp) # print("-----------") # for x in imos: # print(x) print(ans) # 1 3 # 3 4 2
p03504
N,C = list(map(int, input().split())) L = [[int(a) for a in input().split()] for _ in range(N)] ans = [[0, 0] for _ in range(C)] L.sort() for i in range(N): j = 0 while j < C: if ans[j][0] == L[i][0] and ans[j][1] == L[i][2]: ans[j][0] = L[i][1] j = C elif ans[j][0] < L[i][0]: ans[j][0] = L[i][1] ans[j][1] = L[i][2] j = C j += 1 ans.sort(reverse=True) num = 0 for i in range(C): if ans[i][0] > 0: num += 1 print(num)
N,C = list(map(int, input().split())) L = [[int(a) for a in input().split()] for _ in range(N)] ans = [0]*C chan = [0]*C L.sort() for i in range(N): for j in range(C): if ans[j] == L[i][0] and chan[j] == L[i][2]: ans[j] = L[i][1] break elif ans[j] < L[i][0]: ans[j] = L[i][1] chan[j] = L[i][2] break ans.sort(reverse=True) num = 0 for i in range(C): if ans[i] > 0: num += 1 print(num)
p03504
# heapqの方針で上手くいかなかった # 解説放送を見てimosにした def main(): from collections import namedtuple from heapq import heappop, heappush import sys input = sys.stdin.readline Prog = namedtuple('Prog', 'L R') Prog.__eq__ = lambda self, other: self.R == other.R Prog.__lt__ = lambda self, other: self.R < other.R N, C = list(map(int, input().split())) ps = [[] for _ in range(30)] for _ in range(N): l, r, ch = list(map(int, input().split())) heappush(ps[ch - 1], Prog(l, r)) imos = [0] * (10 ** 5 + 1) for ps_ch in ps: while ps_ch: l, r = heappop(ps_ch) while ps_ch and ps_ch[0].L == r: r = ps_ch[0].R heappop(ps_ch) else: imos[l - 1] += 1 imos[r] -= 1 ans = imos[0] for i in range(10 ** 5): imos[i + 1] += imos[i] ans = max(ans, imos[i + 1]) print(ans) if __name__ == '__main__': main()
# heapqの方針で上手くいかなかった # 解説放送を見てimosにした def main(): from collections import namedtuple from heapq import heappop, heappush import sys input = sys.stdin.readline Prog = namedtuple('Prog', 'L R') Prog.__eq__ = lambda self, other: self.R == other.R Prog.__lt__ = lambda self, other: self.R < other.R N, C = list(map(int, input().split())) ps = tuple([] for _ in range(30)) for _ in range(N): l, r, ch = list(map(int, input().split())) heappush(ps[ch - 1], Prog(l, r)) imos = [0] * (10 ** 5 + 1) for ps_ch in ps: while ps_ch: l, r = heappop(ps_ch) while ps_ch and ps_ch[0].L == r: r = ps_ch[0].R heappop(ps_ch) else: imos[l - 1] += 1 imos[r] -= 1 for i in range(10 ** 5): imos[i + 1] += imos[i] print((max(imos))) if __name__ == '__main__': main()
p03504
import copy N,C=list(map(int,input().split())) channel=[tuple(map(int,input().split())) for i in range(N)] channel=sorted(channel,key=lambda cha: cha[0]) n=0 while(channel!=[]): c=copy.copy(channel) n+=1 pro=channel[0] c.remove(pro) for i in channel: if i[0]>pro[1]: pro=i c.remove(pro) channel=c print(n)
N,C=list(map(int,input().split())) channel=[tuple(map(int,input().split())) for i in range(N)] channel=sorted(channel,key=lambda cha: cha[0]) n=0 while(channel!=[]): c=[] n+=1 pro=channel[0] channel.remove(pro) for i in channel: if i[0]>pro[1]: pro=i elif(i[0]==pro[1] and i[2]==pro[2]): pro=i else: c.append(i) channel=c print(n)
p03504
#!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 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): return #D def D(): n,C = LI() T = [[0 for i in range(200002)] for j in range(C)] for i in range(n): s,t,c = LI() c -= 1 T[c][2*s] += 1 T[c][2*t+1] -= 1 for c in range(C): for i in range(200000): T[c][i+1] += T[c][i] ans = 0 for i in range(200000): k = 0 for c in range(C): if T[c][i]:k += 1 ans = max(ans, k) print(ans) #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": D()
#!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 def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A def A(): return #B def B(): return #C def C(): n = I() f = LIR(n) po = [1]*11 for i in range(n): k = 0 p = 1 for j in range(10): k += p*f[i][j] p *= 2 po[j+1] = p f[i] = k p = LIR(n) ans = -float("inf") for i in range(1,1024): k = 0 for j in range(n): c = i&f[j] s = 0 for l in po: if c&l:s += 1 k += p[j][s] ans = max(ans,k) print(ans) #D def D(): n,C = LI() T = [[0 for i in range(100002)] for j in range(C)] for i in range(n): s,t,c = LI() c -= 1 T[c][s] += 1 T[c][t+1] -= 1 for c in range(C): for i in range(100000): T[c][i+1] += T[c][i] ans = 0 for i in range(100000): k = 0 for c in range(C): if T[c][i]:k += 1 ans = max(ans, k) print(ans) #E def E(): return #F def F(): return #G def G(): return #H def H(): return #Solve if __name__ == "__main__": D()
p03504
# -*- coding: utf-8 -*- N, C = list(map(int, input().split())) T = 10**5+2 c_ls = [[0] * T for _ in range(C)] # いもす for i in range(N): s, t, c = list(map(int, input().split())) c_ls[c-1][s] += 1 c_ls[c-1][t] -= 1 # 各チャンネル毎の累積和 for i in range(C): for j in range(1, T): c_ls[i][j] += c_ls[i][j-1] # 他チャンネルとの重複を見るために開始を1早める for i in range(C): for j in range(1, T): if c_ls[i][j] > c_ls[i][j-1]: c_ls[i][j-1] += 1 # 全チャンネルを合計 sm = [0] * T for i in range(C): for j in range(T): sm[j] += c_ls[i][j] # 重複が一番多くなる箇所が答え print((max(sm)))
# -*- coding: utf-8 -*- import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, M = MAP() C = [[] for i in range(M)] for i in range(N): l, r, c = MAP() c -= 1 C[c].append((l, r)) # 同チャンネルで連続する区間をまとめる LR = [] for i in range(M): if C[i]: C[i].sort() LR.append(C[i][0]) for j in range(1, len(C[i])): l1, r1 = C[i][j-1] l2, r2 = C[i][j] if r1 == l2: LR.pop() LR.append((l1, r2)) # 3連続以上を考慮して更新 C[i][j] = (l1, r2) else: LR.append((l2, r2)) # いもす法 MAX = 10 ** 5 + 7 imos = [0] * MAX for l, r in LR: imos[l-1] += 1 imos[r] -= 1 imos = list(accumulate(imos)) print((max(imos)))
p03504
if __name__ == "__main__": n,c = list(map(int, input().split())) timeline = {} for i in range(n): s, t, c = list(map(int, input().split())) for i in range(s-1, t): xs = timeline.get(i, None) if xs is None: xs = set() xs.add(c) timeline[i] = xs print((max([len(v) for k, v in list(timeline.items())])))
def getter(starts, ends): while starts: if starts[-1][0] < ends[-1][1]: yield (starts.pop(), True) else: yield (ends.pop(), False) def foo(C, targets): starts = sorted(targets, key=lambda x:x[0], reverse=True) ends = sorted(targets, key=lambda x: x[1], reverse=True) result = 0 active = [0]*(C+1) for x, p in getter(starts, ends): if p: active[x[2]] += 1 else: active[x[2]] -= 1 result = max(result, sum([1 if x > 0 else 0 for x in active])) return result if __name__ == "__main__": n, C = list(map(int, input().split())) targets = [] for i in range(n): s, t, c = list(map(int, input().split())) targets.append((s-1, t, c)) print((foo(C, targets)))
p03504
N, C, *STC = list(map(int, open(0).read().split())) T = [[0] * 10 ** 5 for _ in range(C + 1)] for s, t, c in zip(*[iter(STC)] * 3): T[c][s - 1:t] = [1] * (t - s + 1) print((max(list(map(sum, list(zip(*T)))))))
def main(): N, C, *STC = list(map(int, open(0).read().split())) T = [[0] * 10 ** 5 for _ in range(C + 1)] for s, t, c in zip(*[iter(STC)] * 3): T[c][s - 1:t] = [1] * (t - s + 1) print((max(list(map(sum, list(zip(*T))))))) main()
p03504
# -*- coding: utf-8 -*- from operator import itemgetter N,C = list(map(int, input().split())) record = [] for _ in range(N): s,t,c = list(map(int, input().split())) record.append((s,t,c)) record.sort(key=itemgetter(1,0,2)) def can_record(k): slots = [(-1,-1)]*k # (end_time, channel) for r in record: idx = -1 t = -1 for i in range(k): end_time, channel = slots[i] if channel==r[2]: if end_time<=r[0]: if t<=end_time: t = end_time idx = i else: if end_time<r[0]: if t<=end_time: t = end_time idx = i if idx==-1: return False else: slots[idx] = (r[1],r[2]) return True for k in range(1,C+1): if can_record(k): print(k) break
# -*- coding: utf-8 -*- from operator import itemgetter N,C = list(map(int, input().split())) T = 0 record = [] for _ in range(N): s,t,c = list(map(int, input().split())) T = max(T, t) record.append((s,t,c)) record.sort(key=itemgetter(2,0,1)) tl = [0]*(T+1) curr_channel = None for r in record: s,t,c = r if curr_channel==c: if curr_time==s: tl[s] += 1 tl[t] -= 1 else: tl[s-1] += 1 tl[t] -= 1 curr_time = t else: tl[s-1] += 1 tl[t] -= 1 curr_channel = c curr_time = t s = 0 res = 0 for t in tl: s += t res = max(res, s) print(res)
p03504
import collections N,C=list(map(int,input().split())) #print N,C d = collections.defaultdict(list) start=float("inf") end=0 for i in range(N): s,t,c=list(map(int,input().split())) d[c].append((s,t)) start=min(start,s) end=max(end,t) #print start,end #print d [d[i].sort() for i in list(d.keys())] #print d c = collections.defaultdict(list) for i in range(start,end): #print "# i" #print i cnt=0 for j in d: for k in d[j]: if i>=k[0] and i<=k[1]: #print j,"Yes" c[i].append(j) break; #print c max_recs=0 for i in list(c.values()): max_recs=max(max_recs,len(i)) print(max_recs)
import collections N,C=list(map(int,input().split())) a=collections.defaultdict(list) max_t=0 for i in range(N): s,t,c=list(map(int,input().split())) a[c].append((s,t)) max_t=max(max_t,t) [a[i].sort() for i in list(a.keys())] #print a #print max_t b=collections.defaultdict(list) for i,j in list(a.items()): start=0 end=0 for k in j: if start==0 and end==0: start=k[0]-1 end=k[1] continue elif k[0]<=end: end=k[1] else: b[i].append((start,end)) start=k[0]-1 end=k[1] else: b[i].append((start,end)) #print "# b" #print b c=[0 for i in range(max_t+2)] for i in list(b.values()): for j,k in i: #print j,1,k+1,-1 c[j]+=1 c[k]-=1 #print c ans=0 sum=0 for i in c: sum+=i ans=max(ans,sum) print(ans)
p03504
import collections N,C=list(map(int,input().split())) a=collections.defaultdict(list) max_t=0 for i in range(N): s,t,c=list(map(int,input().split())) a[c].append((s,t)) max_t=max(max_t,t) [a[i].sort() for i in list(a.keys())] #print a #print max_t b=collections.defaultdict(list) for i,j in list(a.items()): start=0 end=0 for k in j: if start==0 and end==0: start=k[0]-1 end=k[1] continue elif k[0]<=end: end=k[1] else: b[i].append((start,end)) start=k[0]-1 end=k[1] else: b[i].append((start,end)) #print "# b" #print b c=[0 for i in range(max_t+2)] for i in list(b.values()): for j,k in i: #print j,1,k+1,-1 c[j]+=1 c[k]-=1 #print c ans=0 sum=0 for i in c: sum+=i ans=max(ans,sum) print(ans)
# -*- coding: utf-8 -*- import sys from collections import deque N,C=list(map(int, sys.stdin.readline().split())) stc=[ list(map(int, sys.stdin.readline().split())) for _ in range(N)] stc.sort(key=lambda x:(x[0]) ) max_t=max(stc, key=(lambda x: x[1]))[1] channel=[ deque() for _ in range(C+1) ] for s,t,c in stc: try: prev_s,prev_t=channel[c].pop() if prev_t==s: channel[c].append((prev_s,t)) else: channel[c].append((prev_s,prev_t)) channel[c].append((s,t)) except: channel[c].append((s,t)) T=[ 0 for _ in range(max_t+1) ] #時間軸 c=1 for c in range(1,C+1): #チャンネル while channel[c]: s,t=channel[c].pop() for i in range(s,t+1): T[i]+=1 print(max(T))
p03504
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.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from itertools import accumulate N,C = li() MAX = 10**5 stc = [] for _ in range(N): stc.append(list(li())) rec = [[0 for _ in range(MAX+1)] for _ in range(C)] for s,t,c in stc: rec[c-1][s-1] += 1 rec[c-1][t] -= 1 for i in range(C): rec[i] = list(accumulate(rec[i])) rec[i] = [min(1,reci) for reci in rec[i]] rec_total = rec[0] for i in range(1,C): for j in range(MAX+1): rec_total[j] = rec_total[j] + rec[i][j] print((max(rec_total)))
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.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from itertools import accumulate n,ch = li() MAX_T = 10**5+1 program = [[0]*MAX_T for _ in range(ch)] endset = [set() for _ in range(ch)] stc = [] for _ in range(n): s,t,c = li() c -= 1 stc.append((s,t,c)) endset[c].add(t) stc.sort(key=lambda x:x[0]) for s,t,c in stc: if s in endset[c]: program[c][s] += 1 program[c][t] -= 1 else: program[c][s-1] += 1 program[c][t] -= 1 for ci in range(ch): program[ci] = list(accumulate(program[ci])) print((max([sum(time_span) for time_span in zip(*program)])))
p03504
N,C = list(map(int,input().split())) ch = {} for _ in range(N): s,t,c = list(map(int,input().split())) if c not in ch: ch[c] = [0 for _ in range(2*10**5+2)] for i in range(2*s-1,2*t): ch[c][i]=1 cmax = 0 for i in range(2*10**5+2): cnt = 0 for c in ch: if ch[c][i]==1: cnt += 1 cmax = max(cmax,cnt) print(cmax)
N,C = list(map(int,input().split())) G = {i:[0 for _ in range(10**5+1)] for i in range(1,C+1)} for i in range(N): s,t,c = list(map(int,input().split())) G[c][s] += 1 G[c][t] -= 1 F = [0 for _ in range(2*(10**5)+1)] for c in range(1,C+1): for i in range(10**5+1): if G[c][i]==1: F[2*i-1] += 1 elif G[c][i]==-1: F[2*i] -= 1 H = [0 for _ in range(2*(10**5)+1)] for i in range(1,2*(10**5)+1): H[i] = H[i-1]+F[i] print((max(H)))
p03504
N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,input().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5 else: tmp_stc_r = STC[i][0] if rs[j][0] <= tmp_stc_r: if min_idx is None: min_idx = j else: if rs[j][0] < rs[min_idx][0]: min_idx = j if min_idx is None: rs.append([STC[i][1], STC[i][2]]) else: rs[min_idx] = [STC[i][1], STC[i][2]] rs.sort() print((len(rs)))
N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,input().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5 else: tmp_stc_r = STC[i][0] if rs[j][0] <= tmp_stc_r: if min_idx is None: min_idx = j else: if rs[j][0] < rs[min_idx][0]: min_idx = j if min_idx is None: rs.append([STC[i][1], STC[i][2]]) else: rs[min_idx] = [STC[i][1], STC[i][2]] print((len(rs)))
p03504
N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,input().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5 else: tmp_stc_r = STC[i][0] if rs[j][0] <= tmp_stc_r: if min_idx is None: min_idx = j else: if rs[j][0] < rs[min_idx][0]: min_idx = j if min_idx is None: rs.append([STC[i][1], STC[i][2]]) else: rs[min_idx] = [STC[i][1], STC[i][2]] print((len(rs)))
import sys N,C = list(map(int,input().split())) STC = [] for _ in range(N): s,t,c = list(map(int,sys.stdin.readline().split())) STC.append([s,t,c]) STC.sort() rs = [[STC[0][1],STC[0][2]]] for i in range(1,N): len_rs = len(rs) min_idx = None for j in range(len_rs): if rs[j][1] != STC[i][2]: tmp_stc_r = STC[i][0] - 0.5 else: tmp_stc_r = STC[i][0] if rs[j][0] <= tmp_stc_r: if min_idx is None: min_idx = j else: if rs[j][0] < rs[min_idx][0]: min_idx = j if min_idx is None: rs.append([STC[i][1], STC[i][2]]) else: rs[min_idx] = [STC[i][1], STC[i][2]] print((len(rs)))
p03504
n,C = list(map(int,input().split())) INF = float("INF") ch = [[0]*(200001) for _ in range(C)] m = 0 for _ in range(n): s,t,c = list(map(int,input().split())) s = s*2-1 t *= 2 c -= 1 ch[c][s] += 1 ch[c][t] -= 1 m = max(m,t) cnt = [0]*(m+1) for c in range(C): for i in range(1,m+1): ch[c][i] += ch[c][i-1] if ch[c][i-1] == 0 and ch[c][i] > 0: cnt[i] += 1 if ch[c][i-1] > 0 and ch[c][i] == 0: cnt[i] -= 1 for i in range(1,m+1): cnt[i] += cnt[i-1] print((max(cnt)))
n,C = list(map(int,input().split())) ch = [[0]*(200001) for _ in range(C)] m = 0 for _ in range(n): s,t,c = list(map(int,input().split())) s = s*2-1 t *= 2 c -= 1 ch[c][s] += 1 ch[c][t] -= 1 m = max(m,t) cnt = [0]*(m+1) for c in range(C): for i in range(1,m+1): ch[c][i] += ch[c][i-1] if ch[c][i-1] == 0 and ch[c][i] > 0: cnt[i] += 1 if ch[c][i-1] > 0 and ch[c][i] == 0: cnt[i] -= 1 for i in range(1,m+1): cnt[i] += cnt[i-1] print((max(cnt)))
p03504
def func(): tvs = [] for i in range(num): tvs.append((-1, -1)) for i in range(len(bans)): now = bans[i][0] can = bans[i][2] tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can] for j, tv in enumerate(tvs): if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1: del tvs[j] tvs.append((bans[i][1], can)) break else: return False return True n, C = list(map(int, input().split())) bans = [] for i in range(n): bans.append(tuple(map(int, input().split()))) bans.sort(key=lambda x: x[0]) for num in range(1, 1024): if func(): print(num) break
def func(): tvs = [] for i in range(num): tvs.append((-1, -1)) for i in range(len(bans)): now = bans[i][0] can = bans[i][2] # tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can] for j, tv in enumerate(tvs): if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1: del tvs[j] tvs.append((bans[i][1], can)) break else: return False return True n, C = list(map(int, input().split())) bans = [] for i in range(n): bans.append(tuple(map(int, input().split()))) bans.sort(key=lambda x: x[0]) for num in range(1, 1024): if func(): print(num) break
p03504
N, C = list(map(int, input().split())) program = [] program_list = [0 for _ in range((((10 ** 5) * 2) + 10))] for _ in range(C + 1): program.append(program_list.copy()) sm = program_list.copy() s_list = [] t_list = [] c_list = [] for _ in range(N): s, t, c = list(map(int, input().split())) s_list.append(s) t_list.append(t) c_list.append(c) for i in range(1, C + 1): for j in range(len(s_list)): if i == c_list[j]: program[i][(s_list[j] * 2) - 1] += 1 program[i][(t_list[j] * 2)] -= 1 for j in range(1, len(program_list)): program[i][j] += program[i][j - 1] for j in range(0, len(program_list)): if program[i][j] > 0: sm[j] += 1 print((max(sm)))
N, C = list(map(int, input().split())) program = [] program_list = [False for _ in range((((10 ** 5) * 2) + 10))] for _ in range(C + 1): program.append(program_list.copy()) for _ in range(N): s, t, c = list(map(int, input().split())) s2 = (t * 2) - ((s * 2) - 1) program[c][(s * 2) - 1:t * 2] = [True] * s2 max_c = 0 for i in range(len(program_list)): c = 0 for j in range(1, C + 1): if program[j][i]: c += 1 if c > max_c: max_c = c print(max_c)
p03504
N,C = list(map(int,input().split())) T = [[0 for i in range(10**5+1)] for j in range(30)] for i in range(N): s,t,c = list(map(int,input().split())) T[c-1][s] += 1 T[c-1][t] -= 1 for i in range(C): for j in range(10**5): T[i][j+1] += T[i][j] for i in range(C): for j in range(10**5): if T[i][-j-1] == 0 and T[i][-j-2] == 1: T[i][-j-1] = 1 ans = 0 for i in range(10**5+1): ans = max(ans,sum(T[j][i] for j in range(C))) print(ans)
n,c = list(map(int,input().split())) t = [[0 for i in range(100001)] for j in range(c)] for i in range(n): si,ti,ci = list(map(int,input().split())) for j in range(si,ti+1): t[ci-1][j] = 1 ans = 0 for i in range(100001): ans = max(ans,sum(t[j][i] for j in range(c))) print(ans)
p03504
N,C = list(map(int,input().split())) src = [list(map(int,input().split())) for i in range(N)] MAX = 10**5 bucket = [[] for i in range(MAX+2)] bucket2 = [set() for i in range(MAX+2)] for s,t,c in src: bucket[s].append((t,c)) bucket2[s].add(c) imos = [0]*(MAX+2) for s in range(MAX): for t,c in bucket[s]: imos[s-1] += 1 if c in bucket2[t]: imos[t-1] -= 1 else: imos[t] -= 1 ans = tmp = 0 for im in imos: tmp += im ans = max(ans, tmp) print(ans)
N,C = list(map(int,input().split())) STC = [tuple(map(int,input().split())) for i in range(N)] cs = [[] for _ in range(30)] for s,t,c in STC: cs[c-1].append((s,t)) imos = [0]*(100005) for c in cs: c.sort(key=lambda x:x[0]) pt = -1 for s,t in c: if s==pt: imos[s] += 1 else: imos[s-1] += 1 imos[t] -= 1 pt = t for i in range(len(imos)-1): imos[i+1] += imos[i] print((max(imos)))
p03504
N,C = list(map(int,input().split())) P = [[] for i in range(C)] for i in range(N): s,t,c = list(map(int,input().split())) P[c-1].append([s,"S"]) P[c-1].append([t,"T"]) P = [sorted(sorted(P[i],key=lambda x:x[1]),key=lambda x: x[0]) for i in range(C)] #print(P) P2 = [] for i in range(C): for j in range(len(P[i])): if P[i][j][1]=="T": if j!=0: if P[i][j][0]!=P[i][j-1][0]: P2.append(P[i][j]) else: P2.append(P[i][j]) else: if j!=len(P[i])-1: if P[i][j][0]!=P[i][j+1][0]: P2.append([P[i][j][0]-0.5,P[i][j][1]]) else: P2.append([P[i][j][0]-0.5,P[i][j][1]]) P = P2 P = sorted(P,key=lambda x:x[0]) count=0 max_count=0 s_buf = 0 t_buf = 0 prev = -1 for i in range(len(P)): if prev!=P[i][0]: prev=P[i][0] count+=s_buf-t_buf s_buf=0 t_buf=0 max_count=max(count,max_count) if P[i][1]=="S": s_buf+=1 else: t_buf+=1 #print(P) count+=s_buf-t_buf max_count=max(count,max_count) print(max_count)
N,C = list(map(int,input().split())) program_list = [] for i in range(N): s,t,c = list(map(int,input().split())) program_list.append((s-0.5,"s",c-1)) program_list.append((t,"t",c-1)) program_list.sort(key=lambda x:x[0]) c_list=[0 for i in range(C)] count_list=[0 for i in range(C)] max_num=0 for i in range(2*N): if program_list[i][1]=="s": c = program_list[i][2] count_list[c]+=1 c_list[c] = min(1,count_list[c]) max_num=max(sum(c_list),max_num) else: c = program_list[i][2] count_list[c]-=1 c_list[c] = min(1,count_list[c]) print(max_num)
p03504
def LI(): return list(map(int, input().split())) def LS(): return input().split() def I(): return int(eval(input())) def S(): return eval(input()) n, c = LI() l = [] for i in range(n): l.append(LI()) start = 0 end = 0 ans = 0 l.sort(key=lambda x: x[1]) #print(l) while(len(l) > 0): ans += 1 start = l[0][0] end = l[0][1] l = l[1:] if len(l) < 1: break remove_ind = [] for ind, i in enumerate(l): if i[0] > end: start = i[0] end = i[1] remove_ind .append(ind) l = [l[i] for i in range(len(l)) if i not in remove_ind] print(ans)
def LI(): return list(map(int, input().split())) def LS(): return input().split() def I(): return int(eval(input())) def S(): return eval(input()) n, c = LI() l = [] for i in range(n): l.append(LI()) #チャンネル見る必要がある #同じチャンネルで連続しているものはくっつける la = [[[], []] for i in range(c)] for i in l: la[i[2] - 1][0].append(i[0]) la[i[2] - 1][1].append(i[1]) starts = [] ends = [] for s, e in la: wa = set(s).union(set(e)) seki = set(s).intersection(set(e)) a = list(wa.difference(seki)) a.sort() for i, j in zip(a[0::2], a[1::2]): starts.append(i) ends.append(j) s = min(starts) e = max(ends) imos = [0 for i in range(s,e + 2)] for i, j in zip(starts, ends): imos[i - s] += 1 imos[j - s + 1] -= 1 for i in range(len(imos) - 1): imos[i + 1] += imos[i] print((max(imos)))
p03504
n,c = list(map(int,input().split())) arr = [[0 for i in range((10**5+2) * 2)] for i in range(c)] for i in range(n): s,t,ch = list(map(int,input().split())) arr[ch-1][s*2-1] = 1 arr[ch-1][t*2] = -1 for i in range(c): for j in range(1,(10**5+2)*2): arr[i][j] = arr[i][j-1] + arr[i][j] ans = 0 for i in range(((10**5+2)*2)): count = 0 for j in range(c): if arr[j][i] > 0 : count += 1 ans = max(ans,count) print(ans)
n, c = list(map(int, input().split())) r = [[0 for i in range(c)] for j in range(100000)] for dummy in range(n): s, t, c = list(map(int, input().split())) for j in range(s - 1, t): r[j][c - 1] = 1 ans = 0 for i in range(100000): if sum(r[i]) > ans: ans = sum(r[i]) print(ans)
p03504
n,c=[int(i) for i in input().split()] s=[] t=[] for _ in range(n): a=[int(i) for i in input().split()] s.append(a[0]-0.5) t.append(a[1]) s.sort() t.sort() x=0 m=0 while s !=[] or t !=[]: if s==[]: x-=1 del t[0] elif t==[]: x+=1 del s[0] else: if s[0] < t[0]: x+=1 del s[0] else: x-=1 del t[0] m=max(m,x) print(m)
n,c=[int(i) for i in input().split()] s0=[] t0=[] for _ in range(n): a=[int(i) for i in input().split()] s0.append((a[0],a[2])) t0.append((a[1],a[2])) s1=set(s0) t1=set(t0) s2=list(s1.difference(t0)) t2=list(t1.difference(s0)) s=[i[0]-0.5 for i in s2] t=[i[0] for i in t2] s.sort() t.sort() x=0 m=0 si=0 ti=0 while si != len(s): if s[si] < t[ti]: x+=1 si+=1 else: x-=1 ti+=1 m = max(m,x) print(m)
p03504
#!/usr/bin/env python3 N, C = list(map(int, input().split())) table = [[0] * C for i in range(2 * 10 ** 5 + 2)] for i in range(N): s, t, c = list(map(int, input().split())) table[2 * s - 1][c - 1] = 1 table[2 * t][c - 1] = -1 ans = [0] * (2 * 10 ** 5 + 2) for i in range(1, 2 * 10 ** 5 + 2): for j in range(C): if table[i - 1][j] == 1 and table[i][j] == 0: table[i][j] = 1 ans[i] = sum([abs(x) for x in table[i]]) print((max(ans[1:])))
#!/usr/bin/env python3 N, C = list(map(int, input().split())) table = [[0] * C for i in range(10 ** 5 + 1)] for i in range(N): s, t, c = list(map(int, input().split())) table[s - 1][c - 1] += 1 table[t - 1][c - 1] -= 1 imos = [0] * (10 ** 5 + 1) for i in range(10 ** 5 + 1): for j in range(C): if table[i][j] == 1: imos[i] += 1 if table[i][j] == -1: imos[i + 1] -= 1 ans = 0 for i in range(1, 10 ** 5 + 1): imos[i] += imos[i - 1] ans = max(ans, imos[i]) print(ans)
p03504
n, c = list(map(int, input().split())) MAX_COLS = 10**5 table = [[0 for _ in range(MAX_COLS)] for _ in range(c)] for _ in range(n): s, t, i = list(map(int, input().split())) for j in range(s - 1, t - 1): table[i - 1][j] = 1 for i in range(c): for j in range(MAX_COLS - 1): if table[i][j] == 0 and table[i][j + 1] == 1: table[i][j] = 1 res = 0 for j in range(MAX_COLS): count = 0 for i in range(c): count += table[i][j] res = max(res, count) print(res)
n, c = list(map(int, input().split())) MAX_COLS = 10**5 table = [[0 for _ in range(MAX_COLS)] for _ in range(c)] for _ in range(n): s, t, i = list(map(int, input().split())) for j in range(max(0, s - 2), t - 1): table[i - 1][j] = 1 res = 0 for j in range(MAX_COLS): count = 0 for i in range(c): count += table[i][j] res = max(res, count) print(res)
p03504
N,C = list(map(int, input().split())) s =[0]*N t =[0]*N c =[0]*N for i in range(N): s[i],t[i],c[i] = list(map(int, input().split())) imos = [[0]*int(1e5+20) for _ in range(31)] for i in range(N): imos[c[i]][s[i]]+=1 imos[c[i]][t[i]+1]-=1 ans = 0 for i in range(1,int(1e5+10)): sm = 0 for j in range(31): imos[j][i]=imos[j][i-1]+ imos[j][i] if imos[j][i] >= 1: sm+=1 ans = max(ans,sm) print(ans)
N,C = list(map(int, input().split())) s =[0]*N t =[0]*N c =[0]*N for i in range(N): s[i],t[i],c[i] = list(map(int, input().split())) imos = [[0]*int(1e5+20) for _ in range(31)] for i in range(N): imos[c[i]][s[i]]+=1 imos[c[i]][t[i]+1]-=1 ans = 0 for i in range(1,int(1e5+10)): sm = 0 for j in range(C+1): imos[j][i]=imos[j][i-1]+ imos[j][i] if imos[j][i] >= 1: sm+=1 ans = max(ans,sm) print(ans)
p03504
def d_recording(N, C, R): """ N:録画する番組の数 C:テレビが受信できるチャンネルの数 R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc] """ s = [row[0] for row in R] t = [row[1] for row in R] c = [row[2] for row in R] # いつまで録画機を動かすか。0.5を単位時間とするので*2 # 時刻を0からスタートさせるので+2 l = max(t) * 2 + 2 sm = [0 for _ in range(l)] # ある時刻に動いている録画機の数が格納される for i in range(1, C + 1): tt = [0 for _ in range(l)] # チャンネルiを録画しているか否かを格納 # 累積和を取る for j in range(N): if c[j] == i: # 録画開始時刻の0.5前を+1,終了時刻を-1 #(終了時刻は含まないという録画機の条件より、このようにする) tt[s[j] * 2 - 1] += 1 tt[t[j] * 2] -= 1 for j in range(1, l): tt[j] += tt[j - 1] # あるチャンネルを録画している時間帯では、録画機を1個使わねばならない for j in range(l): if tt[j] > 0: sm[j] += 1 ans = max(sm) return ans N,C = [int(i) for i in input().split()] R = [[int(i) for i in input().split()] for j in range(N)] print((d_recording(N, C, R)))
def d_recording(N, C, R): # N:録画する番組の数 # C:テレビが受信できるチャンネルの数 # R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc] from itertools import accumulate start = [row[0] for row in R] end = [row[1] for row in R] channel_num = [row[2] for row in R] # いつまで録画機を動かすか。0.5を単位時間とするので*2 # 時刻を0からスタートさせるので+2 l = max(end) * 2 + 2 running_recorder = [0 for _ in range(l)] # [k]:ある時刻に動作中の録画機の数 for channel in range(1, C + 1): rec = [0 for _ in range(l)] # [k]:チャンネルkを録画しているか否か # 累積和を取る for s, t, c in zip(start, end, channel_num): if c == channel: # 録画開始時刻の0.5前を+1,終了時刻を-1 # (終了時刻は含まないという録画機の条件より、このようにする) rec[s * 2 - 1] += 1 rec[t * 2] -= 1 rec = accumulate(rec) # あるチャンネルを録画している時間帯では、録画機を1個使わねばならない for j, running in enumerate(rec): if running > 0: running_recorder[j] += 1 ans = max(running_recorder) return ans N, C = [int(i) for i in input().split()] R = [[int(i) for i in input().split()] for j in range(N)] print((d_recording(N, C, R)))
p03504
n, c = list(map(int, input().split())) T = 10**5+1 l = [[0]*c for _ in range(T)] for _ in range(n): s, t, c_ = list(map(int, input().split())) c_ -= 1 l[s-1][c_] += 1 l[t][c_] -= 1 for i in range(1, T): for c_ in range(c): l[i][c_] += l[i-1][c_] l[i-1][c_] = min(1, l[i-1][c_]) ans = 0 for i in range(T): ans = max(ans, sum(l[i])) print(ans)
n, c = list(map(int, input().split())) T = 10**5+1 l = [[0]*c for _ in range(T)] for _ in range(n): s, t, c_ = list(map(int, input().split())) c_ -= 1 for i in range(s-1, t): l[i][c_] = 1 ans = 0 for i in range(T): ans = max(ans, sum(l[i])) print(ans)
p03504
import sys input=sys.stdin.buffer.readline n,c=list(map(int,input().split())) a=[ [0 for _ in range(10**5+2)] for _ in range(c)] for _ in range(n): s,t,cc=list(map(int,input().split())) cc-=1 # print(s-1,end=' s-1\n') #a[cc][s-1]+=1 #a[cc][t]-=1 for i in range(s-1,t): a[cc][i]=1 '''for i in range(c): for j in range(1,10**5+1): a[i][j]+=a[i][j-1] ''' ans=1 for j in range(0,10**5+1): su=0 # print(c,'hello') for i in range(c): # print('asdf hello') # print(j,i,a[i][j]) su+=a[i][j] ans=max(ans,su) print(ans)
import sys input=sys.stdin.buffer.readline n,c=list(map(int,input().split())) a=[ [0 for _ in range(10**5+2)] for _ in range(c)] for _ in range(n): s,t,cc=list(map(int,input().split())) cc-=1 # print(s-1,end=' s-1\n') #a[cc][s-1]+=1 #a[cc][t]-=1 for i in range(s-1,t): a[cc][i]=1 '''for i in range(c): for j in range(1,10**5+1): a[i][j]+=a[i][j-1] ''' ans=1 for j in range(0,10**5): su=0 # print(c,'hello') for i in range(c): # print('asdf hello') # print(j,i,a[i][j]) su+=a[i][j] ans=max(ans,su) print(ans)
p03504
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 # if we can record the programms continuously (ver1) if tbl[c][2*s] != 0: tbl[c][2*s] += 1 tbl[c][2*t] -= 1 # if we can record the programms continuously (ver2) elif tbl[c][2*t-1] != 0: tbl[c][2*t-1] -= 1 tbl[c][2*s-1] += 1 # else: else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] # ans = max([sum(x) for x in zip(*tbl2)]) # print(ans) res = 0 for i in range(200002): cc = 0 for j in range(C): if tbl2[j][i] == 1: cc += 1 res = max(res, cc) print(res)
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 # if we can record the programms continuously (ver1) if tbl[c][2*s] != 0: tbl[c][2*s] += 1 tbl[c][2*t] -= 1 # if we can record the programms continuously (ver2) elif tbl[c][2*t-1] != 0: tbl[c][2*t-1] -= 1 tbl[c][2*s-1] += 1 # else: else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] for i in range(200002): for j in range(C): if tbl2[j][i]==2: tbl2[j][i]=1 ans = max([sum(x) for x in zip(*tbl2)]) print(ans) # tmp = [sum(x) for x in zip(*tbl2)] # res = 0 # for i in range(200002): # cc = 0 # for j in range(C): # if tbl2[j][i]: # cc += 1 # res = max(res, cc) # print(res)
p03504
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 # if we can record the programms continuously (ver1) if tbl[c][2*s] == -1: tbl[c][2*s] = 0 tbl[c][2*t] = -1 # if we can record the programms continuously (ver2) elif tbl[c][2*t-1] == 1: tbl[c][2*t-1] = 0 tbl[c][2*s-1] = 1 # else: else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] for i in range(200002): for j in range(C): if tbl2[j][i]>1: tbl2[j][i]=1 ans = max([sum(x) for x in zip(*tbl2)]) print(ans) # tmp = [sum(x) for x in zip(*tbl2)] # res = 0 # for i in range(200002): # cc = 0 # for j in range(C): # if tbl2[j][i]: # cc += 1 # res = max(res, cc) # print(res)
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: list(map(int, r().split())) # set inputs N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 # if we can record the programms continuously (ver1) if tbl[c][2*s] != 0 and tbl[c][2*t-1] != 0: tbl[c][2*s] = 0 tbl[c][2*t-1] = 0 # if we can record the programms continuously (ver2) elif tbl[c][2*s] != 0: tbl[c][2*s] += 1 tbl[c][2*t] -= 1 # if we can record the programms continuously (ver3) elif tbl[c][2*t-1] != 0: tbl[c][2*t-1] -= 1 tbl[c][2*s-1] += 1 # else: else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] ans = max([sum(x) for x in zip(*tbl2)]) print(ans)
p03504
_ = eval(input()) a = [int(i) for i in input().split(' ')] res = 9999999999999999999999999 for i in range(1,len(a)): s = sum(a[:i]) t = sum(a[i:]) temp = abs(s-t) res = min(temp,res) print(res)
import sys n = int(eval(input())) a = [] b = input().split(" ") for i in range(n): a.append(int(b[i])) for i in range(1, n): a[i] += a[i-1] mn = abs(a[n-1] - 2*a[0]) for i in range(1, n-1): mn = min(mn, abs(a[n-1] - 2*a[i])) print(mn)
p03661
# ABC067C - Splitting Pile (ARC078C) def main(): n = int(eval(input())) lst = tuple(map(int, input().rstrip().split())) l, r, ans = 0, sum(lst), float("inf") for i in lst[:-1]: l += i r -= i ans = min(ans, abs(l - r)) print(ans) if __name__ == "__main__": main()
from itertools import accumulate def main(): n = int(eval(input())) lst = tuple(accumulate(list(map(int, input().rstrip().split())))) ans = min(abs(lst[-1] - i * 2) for i in lst[:-1]) print(ans) if __name__ == "__main__": main()
p03661
from itertools import accumulate def main(): n = int(eval(input())) lst = tuple(accumulate(list(map(int, input().rstrip().split())))) ans = min(abs(lst[-1] - i * 2) for i in lst[:-1]) print(ans) if __name__ == "__main__": main()
from itertools import accumulate def main(): n = int(eval(input())) lst = tuple(accumulate(list(map(int, input().rstrip().split())))) total = lst[-1] ans = min(abs(total - i * 2) for i in lst[:-1]) print(ans) if __name__ == "__main__": main()
p03661
n=int(eval(input())) a=list(map(int,input().split())) total=sum(a) x=0 lis=[] for i in range(n-1): x+=a[i] lis.append(abs(2*x-total)) print((min(lis)))
n=int(eval(input())) a=list(map(int,input().split())) total=sum(a) x=0 ans=abs(max(a)-min(a)) for i in range(n-1): x+=a[i] if abs(2*x-total)<ans: ans=abs(2*x-total) print(ans)
p03661
N = int(eval(input())) a = list(map(int, input().split())) S = sum(a) arr = [abs(S - 2*sum(a[:i])) for i in range(1,N)] print((min(arr)))
N = int(eval(input())) a = list(map(int, input().split())) S = sum(a) _min = 10000000000000000000 x = 0 for i in range(0,N-1): x += a[i] tmp = abs(S - 2*x) if tmp < _min: _min = tmp print(_min)
p03661
n,*A=list(map(int,open(0).read().split())) for i in range(n-1):A[i+1]+=A[i] print((min(abs(A[n-1]-A[i]*2)for i in range(n-1))))
n,*A=list(map(int,open(0).read().split())) while n>1:n-=1;A[n-1]+=A[n] print((min(abs(A[0]-e*2)for e in A[1:])))
p03661
def main(): N = int(eval(input())) a = list(map(int, input().split())) #N = 1000 #a = [i for i in range(N)] #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)] summation = [] sumtemp = sum(a) for i in range(len(a)-1): tmp1 = sum(a[:(i+1)]) tmp2 = sumtemp - tmp1 tmp = abs(tmp1 - tmp2) summation.append(tmp) print((min(summation))) main()
def main(): N = int(eval(input())) a = list(map(int, input().split())) #N = 1000 #a = [i for i in range(N)] #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)] summation = [] sumtemp = sum(a) tmp1 = 0 for i in range(len(a)-1): tmp1 += a[i] tmp2 = sumtemp - tmp1 tmp = abs(tmp1 - tmp2) summation.append(tmp) print((min(summation))) main()
p03661
class SegmentTree: def __init__(self, lst, op, e): self.n = len(lst) self.N = 2**((self.n-1).bit_length()) self.op = op # operation self.e = e # identity element self.v = [None]*(2*self.N-1) # construction for i in range(self.N): self.v[i + self.N - 1] = lst[i] if i < self.n else self.e for i in range(self.N - 2, -1, -1): self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2]) # update a_i to be x def update(self, i, x): i += self.N - 1 self.v[i] = x while i > 0: i -= 1 i >>= 1 self.v[i] = self.op(self.v[2*i + 1], self.v[2*i+2]) # returns answer for the query interval [l, r) def query(self, l, r): assert l < r left = l + self.N - 1 right = r + self.N - 1 L = self.e R = self.e while left < right: if left % 2 == 0: # left is even L = self.op(L, self.v[left]) left += 1 if right % 2 == 0: # right is even right -= 1 R = self.op(self.v[right], R) left -= 1 left >>= 1 right >>= 1 return self.op(L, R) N = int(eval(input())) *A, = list(map(int, input().split())) total = sum(A) st = SegmentTree(A, lambda x,y:x+y, 0) ans = 10**18 for i in range(N-1): snuke = st.query(0, i+1) arai = total - snuke ans = min(ans, abs(arai - snuke)) print(ans)
N = int(eval(input())) *A, = list(map(int, input().split())) total = sum(A) snuke = 0 ans = 10**18 for i in range(N-1): snuke += A[i] arai = total - snuke ans = min(ans, abs(arai - snuke)) print(ans)
p03661
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/2/ Solved on 2019/2/ @author: shinjisu """ # ARC 078 C Splitting Pile def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0]*n def getIntLines(n): return [int(input()) for i in range(n)] def getIntMat(n): mat = [] for i in range(n): mat.append(getIntList()) return mat def zeros2(n, m): return [zeros(m)]*n ALPHABET = [chr(i+ord('a')) for i in range(26)] DIGIT = [chr(i+ord('0')) for i in range(10)] N1097 = 10**9 + 7 def dmp(x, cmt=''): global debug if debug: if cmt != '': print(cmt, ': ', end='') print(x) return x def probC(): N = getInt() A = getIntList() dmp((N, A)) diff = 10**(9+6) for i in range(1, N): diff = min(diff, abs(sum(A[:i])-sum(A[i:]))) return diff debug = False # True False ans = probC() print(ans) #for row in ans: # print(row)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/2/ Solved on 2019/2/ @author: shinjisu """ # ARC 078 C Splitting Pile def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0]*n def getIntLines(n): return [int(input()) for i in range(n)] def getIntMat(n): mat = [] for i in range(n): mat.append(getIntList()) return mat def zeros2(n, m): return [zeros(m)]*n ALPHABET = [chr(i+ord('a')) for i in range(26)] DIGIT = [chr(i+ord('0')) for i in range(10)] N1097 = 10**9 + 7 def dmp(x, cmt=''): global debug if debug: if cmt != '': print(cmt, ': ', end='') print(x) return x def probC(): N = getInt() A = getIntList() dmp((N, A)) sumFormer = A[0] sumLatter = sum(A[1:]) diff = abs(sumFormer-sumLatter) dmp(diff,'init') for i in range(1, N-1): sumFormer += A[i] sumLatter -= A[i] diff = min(diff, abs(sumFormer-sumLatter)) return diff def probC_v1(): # 5/16 AC 残りはTLE N = getInt() A = getIntList() dmp((N, A)) diff = 10**(9+6) for i in range(1, N): diff = min(diff, abs(sum(A[:i])-sum(A[i:]))) return diff debug = False # True False ans = probC() print(ans) #for row in ans: # print(row)
p03661
N = int(eval(input())) a = list(map(int,input().split())) cum_sum = [0]*N cum_sum[0] = a[0] for i in range(1,N): cum_sum[i] = cum_sum[i-1] + a[i] res = 10**15 for i in range(N-1): x = cum_sum[i] y = cum_sum[N-1] - cum_sum[i] res = min(res, abs(x-y)) print(res)
N = int(eval(input())) a = list(map(int,input().split())) x = a[0] y = sum(a[1:]) res = abs(x - y) for i in range(1, N - 1): x += a[i] y -= a[i] res = min(res, abs(x - y)) print(res)
p03661
N = eval(input()) a = list(map(int, input().split())) all = sum(a) mini = 10000000000 for i in range(1,N): x = sum(a[:i]) y = all - x ret = abs(x-y) if(ret < mini): mini=ret print(mini)
N = eval(input()) a = list(map(int, input().split())) all = sum(a) mini = 10000000000 x = 0 y = all for i in range(0,N-1): x += a[i] y -= a[i] ret = abs(x-y) if(ret < mini): mini=ret print(mini)
p03661
# -*- coding: utf-8 -*- from itertools import combinations def inpl(): return tuple(map(int, input().split())) N = int(eval(input())) A = inpl() s = sum(A) X = [sum(A[:i]) for i in range(1, N)] print((min([abs(2*x - s) for x in X])))
# -*- coding: utf-8 -*- def inpl(): return tuple(map(int, input().split())) N = int(eval(input())) A = inpl() s = sum(A) x, y = A[0], sum(A[1:]) res = abs(x-y) for a in A[1:-1]: x += a y -= a if abs(x-y) < res: res = abs(x-y) print(res)
p03661
# -*- coding:utf-8 -*- N = int(eval(input())) a = list(map(int, input().split())) b = sum(a) minimum = float('inf') for tmp in range(1,N): c = sum(a[tmp:len(a)]) d = abs(b-2*c) minimum = min(minimum, d) print(minimum)
# -*- coding:utf-8 -*- N = int(eval(input())) a = list(map(int, input().split())) b = sum(a) c = 0 minimum = float('inf') for tmp in range(0,N-1): c += a[tmp] d = abs(c-(b-c)) minimum = min(minimum, d) print(minimum)
p03661
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break print(cnt)
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(array)-1] = tmp if n < len(array) - 1 or target == tmp: cnt += 1 return cnt def linear_search(): cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break def linear_banpei_search(): cnt = 0 for target in T: cnt = search_banpei(S, target, cnt) return cnt cnt = linear_banpei_search() print(cnt)
p02267
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(array)-1] = tmp if n < len(array) - 1 or target == tmp: cnt += 1 return cnt def linear_search(): cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break def linear_banpei_search(): cnt = 0 for target in T: cnt = search_banpei(S, target, cnt) return cnt cnt = linear_banpei_search() print(cnt)
#coding:utf-8 n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) def search_banpei(array, target, cnt): tmp = array[len(array)-1] array[len(array)-1] = target n = 0 while array[n] != target: n += 1 array[len(array)-1] = tmp if n < len(array) - 1 or target == tmp: cnt += 1 return cnt def linear_search(): cnt = 0 for t in T: for s in S: if t == s: cnt += 1 break return cnt def linear_banpei_search(): cnt = 0 for target in T: cnt = search_banpei(S, target, cnt) return cnt cnt = linear_search() print(cnt)
p02267
n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) C = [] for s in S: for t in T: if s == t and not s in C: C.append(s) print((len(C)))
n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) C = 0 for t in T: for s in S: if s == t: C += 1 break print(C)
p02267
def linearSearch(key, list, N): list[N] = key i = 0 while list[i] != key: i += 1 return int(i != N) N1 = int(eval(input())) arr1 = [int(n) for n in input().split()] + [0] N2 = int(eval(input())) arr2 = [int(n) for n in input().split()] print((sum([linearSearch(key, arr1, N1) for key in arr2])))
def linearSearch(key, list): for e in list: if key == e: return 1 return 0 N1 = int(eval(input())) arr1 = [int(n) for n in input().split()] N2 = int(eval(input())) arr2 = [int(n) for n in input().split()] print((sum([linearSearch(key, arr1) for key in arr2])))
p02267
def main(): N = int(eval(input())) S = [int(_) for _ in input().split()] Q = int(eval(input())) T = [int(_) for _ in input().split()] ans = 0 for t in T: for s in S: if s == t: ans += 1 break print(ans) main()
import sys # Set max recursion limit sys.setrecursionlimit(1000000) def li_input(): return [int(_) for _ in input().split()] def main(): n = int(eval(input())) S = li_input() q = int(eval(input())) T = li_input() ans = 0 for t in T: if t in S: ans += 1 print(ans) main()
p02267
n = int(eval(input())) li1 = list(map(int,input().split())) m = int(eval(input())) li2 = list(map(int,input().split())) cnt = 0 for i in li2: if i in li1: cnt +=1 print(cnt)
n = int(eval(input())) S = set(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) sum = 0 for i in T: if i in S: sum +=1 print(sum)
p02267
import sys ERROR_INPUT = 'input is invalid' ERROR_INPUT_NOT_UNIQUE = 'input is not unique' def main(): S = get_input1() T = get_input2() count = 0 for t in T: for s in S: if t == s: count += 1 break print(count) def get_input1(): n = int(eval(input())) if n > 10000: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) li.append(x) return li def get_input2(): n = int(eval(input())) if n > 500: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) elif int(x) in li: print(ERROR_INPUT_NOT_UNIQUE) sys.exit(1) li.append(x) return li main()
import sys ERROR_INPUT = 'input is invalid' ERROR_INPUT_NOT_UNIQUE = 'input is not unique' def main(): S = get_input1() T = get_input2() count = 0 for t in T: if t in S: count += 1 print(count) def get_input1(): n = int(eval(input())) if n > 10000: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) li.append(x) return li def get_input2(): n = int(eval(input())) if n > 500: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) elif int(x) in li: print(ERROR_INPUT_NOT_UNIQUE) sys.exit(1) li.append(x) return li main()
p02267
import sys n = int(sys.stdin.readline()) s = [int(x) for x in sys.stdin.readline().split()] q = int(sys.stdin.readline()) t = [int(x) for x in sys.stdin.readline().split()] cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
import sys n = sys.stdin.readline() s = sys.stdin.readline().split() q = sys.stdin.readline() t = sys.stdin.readline().split() cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
p02267
n = int(eval(input())) s = input().split() q = int(eval(input())) t = input().split() cont = 0 for i in t: for o in s: if i == o: cont +=1 break print(cont)
n = int(eval(input())) s = set(input().split()) q = int(eval(input())) t = set(input().split()) print((len(s & t)))
p02267
def LinearSearch(n, S, t): """ ????????????????????¢????????? """ S.append(t) i = 0 while S[i] != t: i += 1 if i == n: return -1 else: return i n = int(eval(input())) S = [int(s) for s in input().split()] q = int(eval(input())) T = [int(t) for t in input().split()] cnt = 0 for t in T: if LinearSearch(n, S[:], t) != -1: cnt += 1 print(cnt)
def LinearSearch1(S, n, t): for i in range(n): if S[i] == t: return i break else: return -1 """ def LinearSearch2(S, n, t): S.append(t) i = 0 while S[i] != t: i += 1 S.pop() if i == n: return -1 else: return i """ n = int(eval(input())) S = [int(s) for s in input().split()] q = int(eval(input())) T = {int(t) for t in input().split()} ans = sum(LinearSearch1(S, n, t) >= 0 for t in T) print(ans)
p02267
#coding:utf-8 #1_4_A def isFound(array, x): """ linear search """ array.append(x) i = 0 while array[i] != x: i += 1 if i == len(array)-1: return False return True n = int(eval(input())) S = list(map(int, input().split())) q = int(eval(input())) T = list(map(int, input().split())) count = 0 for i in range(q): if isFound(S, T[i]): count += 1 print(count)
#coding:utf-8 #1_4_A n = int(eval(input())) S = set(map(int, input().split())) q = int(eval(input())) T = set(map(int, input().split())) print((len(S & T)))
p02267
a, b = list(map(int, input().split())) res = a - 2*b if res < 0: res = 0 print(res)
a,b = list(map(int, input().split())) res = a - b - b print((0 if res < 0 else res))
p02885
A,B=input().split() A,B=[int(A),int(B)] if(A >= 2*B): print((A-2*B)) else: print((0))
from sys import stdin def main(): #入力 readline=stdin.readline A,B=list(map(int,readline().split())) C=max(0,A-B*2) print(C) if __name__=="__main__": main()
p02885
a,b=list(map(int, input().split())) print((max(a-2*b,0)))
a,b = list(map(int,input().split())) print((max(0,a-b*2)))
p02885
a,b= list(map(int,input().split())) r = a-b*2 if r <= 0: print((0)) else: print(r)
A,B=list(map(int,input().split())) ans=A-B*2 print((ans if ans>=0 else 0))
p02885
a,b = list(map(int,input().split())) if b * 2 >= a: print((0)) else: print((a-2*b))
a,b = list(map(int,input().split())) print((max(0,a-2*b))) ''' if b * 2 >= a: print(0) else: print(a-2*b) '''
p02885
A, B = list(map(int, input().split())) print((A - 2 * B if A - 2 * B > 0 else 0))
A,B = list(map(int, input().split())) print((max(0, A-2*B)))
p02885
a, b = list(map(int, input().split())) ans = a - b * 2 if ans < 0: ans = 0 print (ans)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) a, b = list(map(int, input().split())) ans = a - b * 2 if (ans >= 0): print(ans) else: print((0))
p02885
""" author : halo2halo date : 19,Oct,2019 """ import sys readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 7) A, B = list(map(int, readline().split())) print((max(A-2*B, 0)))
""" author : halo2halo date : 9, Jan, 2020 """ import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) A, B = list(map(int, readline().split())) S=A-2*B print((S if S>0 else 0))
p02885
a,b = list(map(int,input().split())) c = 2*b d = a-c if d > 0: print(d) elif d <= 0: print((0))
a,b = list(map(int,input().split())) if a-2*b > 0: print((a-2*b)) else: print((0))
p02885
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline a, b = list(map(int, input().split())) print((max(0, a - 2 * b))) if __name__ == "__main__": setrecursionlimit(10000) main()
from sys import stdin, setrecursionlimit def main(): input = stdin.buffer.readline a, b = list(map(int, input().split())) if a - 2 * b >= 0: print((a - 2 * b)) else: print((0)) if __name__ == "__main__": setrecursionlimit(10000) main()
p02885
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # input=lambda :sys.stdin.readline().rstrip() def resolve(): a,b=list(map(int,input().split())) print((max(0,a-2*b))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): a,b=list(map(int,input().split())) print((max(0,a-2*b))) resolve()
p02885
a,b = list(map(int,input().split())) print((max(0,a-2*b)))
A,B = list(map(int,input().split())) print((max(0,A-2*B)))
p02885
a,b=list(map(int,input().split())) if 0>a-(2*b): print((0)) else: print((a-(2*b)))
a,b=list(map(int,input().split())) if a<2*b: print((0)) else: print((a-(2*b)))
p02885
a,b=list(map(int,input().split())) if a<2*b: print((0)) else: print((a-(2*b)))
a,b=list(map(int,input().split())) print((max(0,a-2*b)))
p02885
import sys input = sys.stdin.readline a, b = [int(x) for x in input().split()] if 2*b >= a: print((0)) else: print((a - 2*b))
import sys input = lambda : sys.stdin.readline().rstrip() a, b = list(map(int, input().split())) print((max(0, a - 2*b)))
p02885
A, B = list(map(int, input().split())) if A <= B * 2: print('0') else: print((A - 2 * B))
A, B = list(map(int, input().split())) print((max(0, A - 2 * B)))
p02885
a, b = list(map(int, input().split())) if a < b * 2: print((0)) else: print((a-(b*2)))
a, b = list(map(int, input().split())) if a < (b*2): print((0)) else: print((a-(b*2)))
p02885
A,B = list(map(int,input().split())) x = A-B-B print((max(0,x)))
A,B = list(map(int,input().split())) print((max(0, A-B-B)))
p02885
a, b = list(map(int, input().split())) if a > b*2: print((a - b*2)) else: print((0))
a, b = list(map(int, input().split())) print((max(0, a-b*2)))
p02885
A, B = list(map(int, input().split())) space = A - B * 2 if space < 0: space = 0 print(space)
a, b = list(map(int, input().split())) ans = max(a - 2 * b, 0) print(ans)
p02885
A, B = list(map(int, input().split())) print((max(0, A - 2*B)))
a,b=list(map(int,input().split())) print((max(0,a-b-b)))
p02885
a,b=list(map(int,input().split())) d=a-2*b print((d if d>0 else 0))
a,b=list(map(int,input().split())) print((max(0,a-b*2)))
p02885
a,b=list(map(int,input().split())) print((max(0,a-b*2)))
a, b = list(map(int, input().split())) print((max(0, a-2*b)))
p02885
N = int(eval(input())) H = int(eval(input())) W = int(eval(input())) print(((N-H+1)*(N-W+1)))
N = int(eval(input())) H = int(eval(input())) W = int(eval(input())) print(((N-W+1)*(N-H+1)))
p03155
N = int(eval(input())) H = int(eval(input())) W = int(eval(input())) print(((N+1-H)*(N+1-W)))
n = int(eval(input())) h = int(eval(input())) w = int(eval(input())) print(((n+1-h)*(n+1-w)))
p03155
n=int(eval(input())) m=int(eval(input())) h=int(eval(input())) print(((n-m+1)*(n-h+1)))
n,h,w = [int(eval(input())) for _ in range(3)] print(((n-h+1)*(n-w+1)))
p03155
row = [True] * 8 col = [True] * 8 dpos = [True] * 15 dneg = [True] * 15 board = [['.', '.', '.', '.', '.', '.', '.', '.'] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = map(int, line.split()) row[r] = "INIT" col[c] = "INIT" dpos[r + c] = False dneg[r + (7 - c)] = False board[r][c] = 'Q' def dfs(i = 0): if i == 8: for line in board: print(*line, sep='') return if row[i] == "INIT": dfs(i + 1) elif row[i]: for j in range(8): if col[j] == "INIT": pass elif col[j] and dpos[i + j] and dneg[i + (7 - j)]: row[i] = False col[j] = False dpos[i + j] = False dneg[i + (7 - j)] = False board[i][j] = 'Q' dfs(i + 1) row[i] = True col[j] = True dpos[i + j] = True dneg[i + (7 - j)] = True board[i][j] = '.' dfs()
row = [False] * 8 col = [False] * 8 dpos = [False] * 15 dneg = [False] * 15 board = [['.', '.', '.', '.', '.', '.', '.', '.'] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = list(map(int, line.split())) row[r] = True col[c] = True dpos[r + c] = True dneg[r - c + 7] = True board[r][c] = 'Q' def dfs(i = 0): if i == 8: for line in board: print((''.join(line))) elif row[i]: dfs(i + 1) else: for j in range(8): if col[j] or dpos[i + j] or dneg[i - j + 7]: continue row[i] = True col[j] = True dpos[i + j] = True dneg[i - j + 7] = True board[i][j] = 'Q' dfs(i + 1) row[i] = False col[j] = False dpos[i + j] = False dneg[i - j + 7] = False board[i][j] = '.' dfs()
p02244
import sys; def putQueen(i, row, col, dpos, dneq): if(i == 8): global finding if(finding == 0): return finding = 0 printBoard(row[0:]) for j in range(8): if i in myset: putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:]) continue if(col[j] == 1 or dpos[i+j] == 1 or dneq[i-j+7] == 1): continue row[i] = j col[j] = dpos[i+j] = dneq[i-j+7] = 1 putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:]) col[j] = dpos[i+j] = dneq[i-j+7] = 0 def printBoard(row): for k in range(8): if(row[k] == 0): print("Q.......") elif(row[k] == 1): print(".Q......") elif(row[k] == 2): print("..Q.....") elif(row[k] == 3): print("...Q....") elif(row[k] == 4): print("....Q...") elif(row[k] == 5): print(".....Q..") elif(row[k] == 6): print("......Q.") else: print(".......Q") n = (int)(eval(input())); row = [0 for i in range(8)] col = [0 for i in range(8)] dpos = [0 for i in range(15)] dneq = [0 for i in range(15)] myset = set() for i in range(n): r,c = list(map(int, input().split())); myset.add(r) row[r] = c col[c] = 1 dpos[r+c] = 1 dneq[r-c+7] = 1 finding = 1 putQueen(0,row, col, dpos, dneq)
import sys; def putQueen(i, row, col, dpos, dneq): global finding if(finding == 0): return if(i == 8): finding = 0 printBoard(row[0:]) return for j in range(8): if i in myset: putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:]) continue if(col[j] == 1 or dpos[i+j] == 1 or dneq[i-j+7] == 1): continue row[i] = j col[j] = dpos[i+j] = dneq[i-j+7] = 1 putQueen(i+1,row[0:], col[0:], dpos[0:], dneq[0:]) col[j] = dpos[i+j] = dneq[i-j+7] = 0 def printBoard(row): for k in range(8): if(row[k] == 0): print("Q.......") elif(row[k] == 1): print(".Q......") elif(row[k] == 2): print("..Q.....") elif(row[k] == 3): print("...Q....") elif(row[k] == 4): print("....Q...") elif(row[k] == 5): print(".....Q..") elif(row[k] == 6): print("......Q.") else: print(".......Q") n = (int)(eval(input())); row = [0 for i in range(8)] col = [0 for i in range(8)] dpos = [0 for i in range(15)] dneq = [0 for i in range(15)] myset = set() for i in range(n): r,c = list(map(int, input().split())); myset.add(r) row[r] = c col[c] = 1 dpos[r+c] = 1 dneq[r-c+7] = 1 finding = 1 putQueen(0,row, col, dpos, dneq)
p02244
import itertools N, Q, row, col = eval(input()), [], list(range(8)), list(range(8)) for _ in range(N): r, c = list(map(int, input().split())) Q.append((r, c)) row.remove(r) col.remove(c) for l in itertools.permutations(col): queen = Q + list(zip(row, l)) if not any(any((r1 != r2 or c1 != c2) and (r1 == r2 or c1 == c2 or r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2) for r2, c2 in queen) for r1, c1 in queen): print('\n'.join(''.join('Q' if (r, c) in queen else '.' for c in range(8)) for r in range(8))) break
import itertools N, Q, row, col = eval(input()), [], list(range(8)), list(range(8)) for _ in range(N): r, c = list(map(int, input().split())) Q.append((r, c)) row.remove(r) col.remove(c) for l in itertools.permutations(col): queen = Q + list(zip(row, l)) if not any((r1 != r2 or c1 != c2) and (r1 == r2 or c1 == c2 or r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2) for r2, c2 in queen for r1, c1 in queen): print('\n'.join(''.join('Q' if (r, c) in queen else '.' for c in range(8)) for r in range(8))) break
p02244
from sys import stdin N = 8 FREE = -1 NOT_FREE = 1 row = [FREE] * N col = [FREE] * N dpos = [FREE] * (2 * N - 1) dneg = [FREE] * (2 * N - 1) X = [[False] * N for _ in range(N)] n = int(stdin.readline()) for _ in range(0, n): r, c = list(map(int, stdin.readline().split())) X[r][c] = True def printBoard(): for i in range(0, N): for j in range(0, N): if X[i][j] != 0 and row[i] != j: return for i in range(0, N): print((''.join(('Q' if row[i] == j else '.' for j in range(N))))) def recursive(i): if i == N: printBoard() return for j in range(0, N): if (NOT_FREE == col[j] or NOT_FREE == dpos[i + j] or NOT_FREE == dneg[i - j + N - 1]): continue row[i] = j col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE recursive(i + 1) row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE recursive(0)
from sys import stdin N = 8 FREE = -1 NOT_FREE = 1 row = [FREE] * N col = [FREE] * N dpos = [FREE] * (2 * N - 1) dneg = [FREE] * (2 * N - 1) X = [[False] * N for _ in range(N)] n = int(stdin.readline()) for _ in range(0, n): r, c = list(map(int, stdin.readline().split())) X[r][c] = True def printBoard(): for i in range(0, N): for j in range(0, N): if X[i][j] != 0 and row[i] != j: return for i in range(0, N): print(("." * row[i] + "Q" + "." * (8 - row[i] - 1))) def recursive(i): if i == N: printBoard() return for j in range(0, N): if (NOT_FREE == col[j] or NOT_FREE == dpos[i + j] or NOT_FREE == dneg[i - j + N - 1]): continue row[i] = j col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE recursive(i + 1) row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE recursive(0)
p02244
from sys import stdin N = 8 FREE = -1 NOT_FREE = 1 row = [FREE] * N col = [FREE] * N dpos = [FREE] * (2 * N - 1) dneg = [FREE] * (2 * N - 1) X = [[False] * N for _ in range(N)] n = int(stdin.readline()) for _ in range(0, n): r, c = list(map(int, stdin.readline().split())) X[r][c] = True def printBoard(): for i in range(0, N): for j in range(0, N): if X[i][j] != 0 and row[i] != j: return for i in range(0, N): print(("." * row[i] + "Q" + "." * (8 - row[i] - 1))) def recursive(i): if i == N: printBoard() return for j in range(0, N): if (NOT_FREE == col[j] or NOT_FREE == dpos[i + j] or NOT_FREE == dneg[i - j + N - 1]): continue row[i] = j col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE recursive(i + 1) row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE recursive(0)
from sys import stdin from itertools import permutations as per def check(queen): for r1, c1 in queen: if not all((r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2) for r2, c2 in queen): return False return True k = int(stdin.readline()) R, C = [[i for i in range(8)] for _ in range(2)] q = [] for _ in range(k): r, c = list(map(int, stdin.readline().split())) q.append((r, c)) R.remove(r) C.remove(c) for l in per(C): q_tmp = q[:] + [(r, c) for r, c in zip(R, l)] if check(q_tmp): for i, j in sorted(q_tmp): print(("." * j + "Q" + "." * (8 - j - 1))) break
p02244
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] @lru_cache(maxsize=None) def dia(s,a,b): d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: d.append(s[i][j]) if j - (a - i) == b: d.append(s[i][j]) if j + (i - a) == b: d.append(s[i][j]) if j - (i - a) == b: d.append(s[i][j]) except IndexError: continue print(d) return d def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: d.append(cc[i][j]) if j - (a - i) == b: d.append(cc[i][j]) if j + (i - a) == b: d.append(cc[i][j]) if j - (i - a) == b: d.append(cc[i][j]) except IndexError: continue if 'Q' in d: return False return True def chess(s,queen): if queen == 8: return s for i in range(8): for j in range(8): if check(s,i,j): sol = s sol[i][j] = 'Q' if chess(sol,queen+1) != [[]]: return sol else: sol[i][j] = "." return [[]] k = int(eval(input())) for i in range(k): a, b = input().split() cc[int(a)][int(b)] = 'Q' ans = chess(cc,k) print(('\n'.join(list([''.join(x) for x in ans])) ))
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: d.append(cc[i][j]) if j - (a - i) == b: d.append(cc[i][j]) if j + (i - a) == b: d.append(cc[i][j]) if j - (i - a) == b: d.append(cc[i][j]) except IndexError: continue if 'Q' in d: return False return True def chess(s,queen): if queen == 8: return s for i in range(8): for j in range(8): if check(s,i,j): sol = s sol[i][j] = 'Q' if chess(sol,queen+1) != [[]]: return sol else: sol[i][j] = "." return [[]] k = int(eval(input())) for i in range(k): a, b = input().split() cc[int(a)][int(b)] = 'Q' ans = chess(cc,k) print(('\n'.join(list([''.join(x) for x in ans])) ))
p02244
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + (a - i) == b: d.append(cc[i][j]) if j - (a - i) == b: d.append(cc[i][j]) if j + (i - a) == b: d.append(cc[i][j]) if j - (i - a) == b: d.append(cc[i][j]) except IndexError: continue if 'Q' in d: return False return True def chess(s,queen): if queen == 8: return s for i in range(8): for j in range(8): if check(s,i,j): sol = s sol[i][j] = 'Q' if chess(sol,queen+1) != [[]]: return sol else: sol[i][j] = "." return [[]] k = int(eval(input())) for i in range(k): a, b = input().split() cc[int(a)][int(b)] = 'Q' ans = chess(cc,k) print(('\n'.join(list([''.join(x) for x in ans])) ))
from functools import lru_cache cc = [["." for i in range(8)] for j in range(8)] def check(cc,a,b): ss = list(zip(*cc)) if 'Q' in cc[a]: return False if 'Q' in ss[b]: return False d = [] for i in range(8): for j in range(8): try: if j + abs(a - i) == b: d.append(cc[i][j]) if j - abs(a - i) == b: d.append(cc[i][j]) except IndexError: continue if 'Q' in d: return False return True def chess(s, queen): if queen == 8: return s for i in range(8): for j in range(8): if check(s, i, j): sol = s sol[i][j] = 'Q' if chess(sol, queen+1) != [[]]: return sol else: sol[i][j] = "." return [[]] k = int(eval(input())) for i in range(k): a, b = [int(x) for x in input().split()] cc[a][b] = 'Q' ans = chess(cc, k) print(('\n'.join(list([''.join(x) for x in ans])) ))
p02244
L = list(map(int, input().split())) maxres = 0 for i in range(3): n = [1, 0, -1] if L[i] <= L[3]: maxres += L[i] * n[i] L[3] -= L[i] else: for j in range(L[3]): maxres += n[i] L[3] -= 1 print(maxres)
L = list(map(int, input().split())) n = [1, 0, -1] maxres = 0 for i in range(3): if L[3] == 0: break maxres += L[i] * n[i] L[3] -= L[i] #print(L[3]) if L[3] < 0: maxres -= abs(L[3]) * n[i] break print(maxres)
p02682
A, B, C, K = list(map(int, input().split())) point = 0 judge = False if A == K: point = A judge = True elif A == 0 and B == K: point = 0 judge = True elif A == 0 and B == 0 and C == K: point = -K judge = True if not judge: if A > 0 and K > 0: while A > 0 and K > 0: K -= 1 A -= 1 point += 1 if B > 0 and K > 0: while B > 0 and K > 0: K -= 1 B -= 1 point += 0 if C > 0 and K > 0: while C > 0 and K > 0: K -= 1 C -= 1 point -= 1 print(point)
a,b,c,k=list(map(int,input().split()));count=0 if k<=a: print(k) elif k<=a+b: print(a) else: print((a-(k-a-b)))
p02682
a,b,c,k = list(map(int,input().split())) res = 0 if a > 0: if a <= k: res += a k -= a elif a > k: while k > 0: res += 1 k -= 1 if k > 0 and b > 0: if b <= k: k -= b elif b > k: k = 0 if k > 0 and c > 0: if c <= k: res -= c k -= c elif c > k: while k > 0: res -= 1 k -= 1 print(res)
a,b,c,k = list(map(int,input().split())) res = 0 if a > 0: if a <= k: res += a k -= a elif a > k: res += k k = 0 if k > 0 and b > 0: if b <= k: k -= b elif b > k: k = 0 if k > 0 and c > 0: if c <= k: res -= c k -= c elif c > k: res -= k k = 0 print(res)
p02682
from collections import * A, B, C, K = list(map(int, input().split())) if K<=A: print(K) elif K<=A+B: print(A) else: print((A-(K-A-B)))
A, B, C, K = list(map(int, input().split())) if K<A: print(K) elif K<A+B: print(A) else: print((A-(K-A-B)))
p02682
a, b, c, k = list(map(int, input().split())) res = 0 i = 0 a_times = 0 b_times = 0 c_times = 0 if a == k: a_times = k else: for i in range(k): # print('i = ', i) if i < a: a_times += 1 # print('res + 1= ', res) elif i + a < a + b: b_times += 1 # print('res + 0 = ', res) elif i + a + b < a + b + c: c_times += 1 # print('res - 1 = ', res) print((a_times * 1 + b_times * 0 + c_times * -1))
a, b, c, k = list(map(int, input().split())) a_times = 0 b_times = 0 c_times = 0 if a <= k: a_times = a # print('a_times = ', a_times) if a_times + b <= k: b_times = b # print('if - b_times = ', b_times) else: b_times = k - a_times # print('else - b_times = ', b_times) if a_times + b_times + c <= k: c_times = c # print('if - c_times = ', c_times) else: c_times = k - a_times - b_times # print('else - c_times = ', c_times) else: a_times = k print((a_times * 1 + b_times * 0 + c_times * -1))
p02682
A, B, C, K = list(map(int, input().split())) sum = 0 if A <= K: K -= A sum += 1 * A elif K > 0: sum += 1 * K K = 0 if B <= K: K -= B elif K > 0: K = 0 if C <= K: K -= C sum -= 1 * C elif K > 0: sum -= 1 * K print(sum)
a, b, c, k = list(map(int, input().split())) if k <= a: print(k) elif k <= a + b: print(a) else: print((a - (k - (a + b))))
p02682
a,b,c,k=list(map(int,input().split())) if a>=k: print(k) else: if a+b>=k: print(a) else: if a+b+c>=k: print((a-(k-(a+b))))
a,b,c,k=list(map(int,input().split())) if a>=k: print(k) elif a+b>=k: print(a) else: print((a-(k-(a+b))))
p02682
def main(): A, B, C, K = list(map(int, input().split())) v = 0 if K <= A: return K elif K <= A+B: return A else: return A - (K-A-B) if __name__ == '__main__': print((main()))
def main(): A, B, C, K = list(map(int, input().split())) if K <= A: return K elif K <= A+B: return A else: return A - (K-A-B) if __name__ == '__main__': print((main()))
p02682
A, B, C, K = list(map(int, input().split())) a = min(A, K) K -= a b = min(B, K) K -= b c = K print((a-c))
a, b, c, k = list(map(int, input().split())) ans = 0 ans += min(a,k) k -= min(a,k) ans += min(b,k)*0 k -= min(b,k) ans += k*(-1) print(ans)
p02682
a,b,c,k=list(map(int,input().split())) if a>=k: print(k) elif a<k: if k-a<=b: print(a) elif k-a >b: print((a-(k-a-b)))
a,b,c,k=list(map(int,input().split())) ans=0 ans=min(k,a) k-=min(k,a) ans+=min(k,b)*0 k-=min(k,b) ans+=min(k,c)*(-1) print(ans)
p02682
a,b,c,k=list(map(int,input().split())) if k<=a+b: print(a) for i in range(1,c): if k==a+b+i: print((a-i))
a,b,c,k=list(map(int,input().split())) def calc(a,b,c,k): if k<a: return k elif k<=a+b: return a else: return a-(k-a-b) print((calc(a,b,c,k)))
p02682