input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys input = sys.stdin.readline N, W = list(map(int, input().split())) wv = [[int(i) for i in input().split()] for _ in range(N)] def knapsack(i, w) : if i == N : return 0 M = knapsack(i + 1, w) if w >= wv[i][0] : M = max(M, knapsack(i + 1, w - wv[i][0]) + wv[i...
import sys input = sys.stdin.readline N, W = list(map(int, input().split())) wv = [[int(i) for i in input().split()] for _ in range(N)] s = [[] for _ in range(4)] w0 = wv[0][0] for w, v in wv : s[w-w0].append(v) for i in range(4) : s[i].sort(reverse=True) s[i] = [0] + s[i] for j in range(...
p03732
# -*- coding: utf-8 -*- """ 参考:https://img.atcoder.jp/arc073/editorial.pdf    https://ei1333.hateblo.jp/entry/2017/05/01/004235    https://atcoder.jp/contests/abc060/submissions/3782609 ・公式解 ・累積和あり """ import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(10 ** 9) from colle...
# -*- coding: utf-8 -*- """ 参考:https://atcoder.jp/contests/abc060/submissions/3958560 ・前から普通にDPもdictでやってみる。 """ import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(10 ** 9) from collections import defaultdict N, W = list(map(int, input().split())) wN = [0] * N vN = [0] *...
p03732
import sys from collections import defaultdict, deque def main(): input = sys.stdin.readline N, W = list(map(int, input().split())) A = [tuple(map(int, input().split())) for _ in range(N)] d = defaultdict(lambda: 0) q = deque() for a in A: while len(q) > 0: w0, ...
# Editorial import sys from itertools import accumulate def main(): input = sys.stdin.readline N, W = list(map(int, input().split())) V = [[] for _ in range(4)] w0, v0 = list(map(int, input().split())) V[0].append(v0) for _ in range(N-1): w, v = list(map(int, input().spli...
p03732
from collections import defaultdict N,W=list(map(int,input().split())) a=defaultdict(lambda:[]) for i in range(N): w,v=list(map(int,input().split())) a[w]=a[w]+[v] for i,j in list(a.items()): a[i]=sorted(j,reverse=True) lst=[] for i,j in list(a.items()): lst.append( (i,len(j)) ) max_val=0 if...
from collections import defaultdict N,W=list(map(int,input().split())) wv=[] for i in range(N): w,v=list(map(int,input().split())) wv.append((w,v)) dp=defaultdict(lambda: 0) # Weight:Value dp[0]=0 for w1,v1 in wv: d=dp.copy() for w,v in list(dp.items()): dp[w+w1]=max( dp[w+w1], d[w]+v1 ) l...
p03732
N, W = list(map(int, input().split())) data = tuple(tuple(map(int, input().split())) for _ in range(N)) table = [dict() for _ in range(N + 1)] table[0][0] = 0 for n in range(N): weight, value = data[n] for w, now in list(table[n].items()): table[n + 1][w] = max(table[n + 1].get(w, 0), now) ...
N, W = list(map(int, input().split())) data = tuple(tuple(map(int, input().split())) for _ in range(N)) d = {0: 0} for n in range(N): weight, value = data[n] for w, now in list(d.copy().items()): if w + weight <= W: d[w + weight] = max(d.get(w + weight, 0), now + value) print((max(d....
p03732
#入力 n, W=list(map(int, input().split())) w,v=[],[] for i in range(n): a,b=list(map(int,input().split())) w.append(a) v.append(b) # i番目以降から重さの総和がj 以下になるように選んだ時の重量 def rec(i,j): #既に計算されているなら、メモdp[][]を受け取る if dp[i][j]>=0: return dp[i][j] if i==n:#もう品物がないから終わり res=0 elif w[i]>j:#i番目の荷物...
N, W = list(map(int, input().split())) value_table = [[] for i in range(4)] for i in range(N): w, v = list(map(int,input().split())) if i == 0: w1 = w value_table[w-w1] += [v] [value_table[i].sort(reverse=True) for i in range(4)] ans = 0 value_table_ruiseki = [[0] for i in range(4)] ...
p03732
N,W=list(map(int,input().split())) v=[[],[],[],[]] kosu=[0,0,0,0] kr=list(map(int,input().split())) v[0].append(kr[1]) w0=kr[0] for i in range(1,N): kr=list(map(int,input().split())) v[kr[0]-w0].append(kr[1]) for i in range(4): v[i].sort() v[i].reverse() kos=[len(v[0]),len(v[1]),len(v[2]),le...
N,W=list(map(int,input().split())) v=[[],[],[],[]] kosu=[0,0,0,0] kr=list(map(int,input().split())) v[0].append(kr[1]) w0=kr[0] for i in range(1,N): kr=list(map(int,input().split())) v[kr[0]-w0].append(kr[1]) for i in range(4): v[i].sort() v[i].reverse() kos=[len(v[0]),len(v[1]),len(v[2]),le...
p03732
n,W = list(map(int,input().split())) w = [0]*n v = [0]*n for i in range(n): w[i],v[i] = list(map(int,input().split())) x = w[0] for i in range(n): w[i] -= x dp = [[[0]*(4*n+1) for _ in range(n+1)] for _ in range(n+1)] for i in range(n): for j in range(i+1): for k in range(4*n+1): if ...
n,W = list(map(int,input().split())) lst = [[0]*(n+1) for _ in range(4)] for i in range(n): w,v = list(map(int,input().split())) if i == 0: x = w lst[w-x].append(v) for i in range(4): lst[i].sort(reverse=True) for j in range(n): lst[i][j+1] += lst[i][j] ans = 0 for a in range(n+1): fo...
p03732
N, W = list(map(int, input().split())) weights = [] values = [] for i in range(N): lst = [int(e) for e in input().split()] weights.append(lst[0]) values.append(lst[1]) #df = np.array(ary) def rec(i, j): if i == N: return 0 elif j < weights[i]: return rec(i+1, j) ...
N, W = list(map(int, input().split())) weights = [] values = [] for i in range(N): lst = [int(e) for e in input().split()] weights.append(lst[0]) values.append(lst[1]) dp = [{} for j in range(N+1)] def rec(i, j): if j in dp[i]: return dp[i][j] res = 0 if i == N: ...
p03732
from collections import * N,W = list(map(int,input().split())) dp = defaultdict(int) dp[0] = 0 for n in range(N): w,v = list(map(int,input().split())) for k,b in list(dp.copy().items()): if k+w<=W: dp[k+w] = max(dp[k+w],b+v) print((max(dp.values())))
from collections import * N,W = list(map(int,input().split())) dp = defaultdict(int) dp[0] = 0 for n in range(N): w1,v1 = list(map(int,input().split())) for w2,v2 in list(dp.copy().items()): if w1+w2<=W: dp[w1+w2] = max(dp[w1+w2],v1+v2) print((max(dp.values())))
p03732
from collections import defaultdict n, W = list(map(int, input().split())) dd = defaultdict(list) for i in range(n): weight, value = list(map(int, input().split())) dd[weight].append(value) a = min(dd.keys()) b, c, d = a+1, a+2, a+3 Vcum = defaultdict(lambda: [0]) for k in [a, b, c, d]: s = 0 ...
from collections import defaultdict n, W = list(map(int, input().split())) dd = defaultdict(list) for i in range(n): weight, value = list(map(int, input().split())) dd[weight].append(value) a = min(dd.keys()) b, c, d = a+1, a+2, a+3 Vcum = defaultdict(lambda: [0]) for k in [a, b, c, d]: s = 0 ...
p03732
n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] dp = [[[-1] * (3 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)] dp[0][0][0] = 0 w1 = wv[0][0] for i, (w, v) in enumerate(wv): for j in range(i + 1): for k in range(3 * n + 1): if d...
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc =...
p03732
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc =...
from itertools import accumulate n, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] w1 = wv[0][0] weights = [[] for _ in range(4)] for w, v in wv: w_diff = w - w1 weights[w_diff].append(v) for i in range(4): weights[i].sort(reverse=True) acc =...
p03732
N, W = list(map(int, input().split())) wv = [list(map(int, input().split())) for i in range(N)] w1 = wv[0][0] w_to_idx = {0:0} idx_to_w = {0:0} idx_W = 0 def calc(): global w_to_idx, idx_to_w, idx_W idx = 1 w_max = 0 for i in range(1, N+1): w = w1*i for j in range(3*i + 1): ww = w +...
from itertools import accumulate N, W = list(map(int, input().split())) wv = {} w1 = 0 for i in range(N): w, v = list(map(int, input().split())) if i == 0: w1 = w if w in wv: wv[w].append(v) else: wv[w] = [v] for w in wv: wv[w].sort(reverse=True) wv[w] = [0] + list(accumulate(w...
p03732
def d_simple_knapsack(N, W, Baggage): from collections import defaultdict # dp[w]:ナップサックに重さがwになるように荷物を入れたときの価値の最大値 dp = defaultdict(int) dp[0] = 0 # 重さ0で達成できる価値は0とする for w, v in Baggage: # dpの各要素(現時点におけるナップサック内の荷物の重さ)に対して、 # 注目した荷物を入れても重さがWを超えなければ、 # ナップサックに荷物を入れて価値の...
def d_simple_knapsack(N, W, Baggage): from collections import defaultdict # dp[w]:ナップサックに重さがwになるように荷物を入れたときの価値の最大値 dp = defaultdict(int) dp[0] = 0 # 重さ0で達成できる価値は0とする for w, v in Baggage: # dpの各要素(現時点におけるナップサック内の荷物の重さ)に対して、 # 注目した荷物を入れても重さがWを超えなければ、 # ナップサックに荷物を入れて価値の...
p03732
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def solve1(N, W, weight, value): dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): for w in range(W + 1): ...
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, W, *wv = list(map(int, read().split())) w0 = wv[0] weight = [[] for _ in range(4)] ...
p03732
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, W, *WV = list(map(int, read().split())) weight = WV[::2] value = WV[1::2] w_min...
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, W, *WV = list(map(int, read().split())) weight = WV[::2] value = WV[1::2] w_min...
p03732
n, w = list(map(int, input().split())) items = [list(map(int, input().split())) for _ in range(n)] if w < items[0][0] : print((0)) exit() w_sum = 0 v_sum = 0 for i in range(n): w_sum += items[i][0] v_sum += items[i][1] if w >= w_sum: print(v_sum) exit() dp = {} #for j in range(1,w+...
N,W=list(map(int,input().split())) dp=[[-1]*301 for i in range(N+1)] dp[0][0]=0 for i in range(N): w,v=list(map(int,input().split())) if i==0: base=w for i in range(N)[::-1]: for j in range(301)[::-1]: if dp[i][j]!=-1: dp[i+1][j+w-base]=max(dp[i][j]+v,...
p03732
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) ...
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) ...
p03732
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) ...
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) ...
p03732
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) ...
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1]) wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): if wv[i][0]==w0: k=wv[i][1]+x[0][-1] l=len(x[0]) if l*w0<=w:x[0].append(k) ...
p03732
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].a...
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].a...
p03732
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].a...
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].a...
p03732
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].a...
n,w=list(map(int,input().split())) wv=[list(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].a...
p03732
from operator import itemgetter n,w=list(map(int,input().split())) wv=[tuple(map(int,input().split())) for i in range(n)] wv.sort(key=itemgetter(1),reverse=True)#reverse wv.sort(key=itemgetter(0)) #print(wv) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=le...
n,w=list(map(int,input().split())) wv=[tuple(map(int,input().split())) for i in range(n)] wv.sort(key=lambda x:-x[1])#reverse wv.sort(key=lambda x:x[0]) w0=wv[0][0] x=[[0],[0],[0],[0]] for i in range(n): z=wv[i][0]-w0 k=wv[i][1]+x[z][-1] l=len(x[z]) if l*wv[i][0]<=w: x[z].append(k) ...
p03732
n,w=list(map(int,input().split())) w_sub,v_sub=list(map(int,input().split())) w0=w_sub inf=1000000001 x=[[inf,v_sub],[inf],[inf],[inf]] for i in range(n-1): w_sub,v_sub=list(map(int,input().split())) w_sub-=w0 x[w_sub].append(v_sub) for i in range(4): x[i].sort(key=lambda x:-x) x[i][0]=0 ...
import sys input = sys.stdin.readline n,w=list(map(int,input().split())) w_sub,v_sub=list(map(int,input().split())) w0=w_sub inf=1000000001 x=[[inf,v_sub],[inf],[inf],[inf]] for i in range(n-1): w_sub,v_sub=list(map(int,input().split())) z=w_sub-w0 x[z].append(v_sub) for i in range(4): x[i]....
p03732
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in...
eps = 1.0 / 10**10 def LI(): return [int(x) for x in input().split()] def main(): n,q = LI() na = [LI() for _ in range(n)] qa = [LI() for _ in range(q)] rr = [] def k(a,b): return sum([(a[i]-b[i]) ** 2 for i in range(3)]) ** 0.5 def f(a,b,c,r): ab = k(a,b) ...
p01753
n,m=[int(i) for i in input().split()] A=[] b=[] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(eval(input()))) for i in range(n): s=0 for j in range(m): s+=A[i][j]*b[j] print(s)
a,b=list(map(int,input().split())) A=[] B=[] for i in range(a): A.append([int(j) for j in input().split()]) for i in range(b): B.append(int(eval(input()))) for i in range(a): s=0 for j in range(b): s+=A[i][j]*B[j] print(s)
p02410
[n, m] = [int(x) for x in input().split()] A = [[0] * m for x in range(n)] B = [0] * m counter = 0 while counter < n: A[counter] = [int(x) for x in input().split()] counter += 1 counter = 0 while counter < m: B[counter] = int(input()) counter += 1 counter = 0 while counter < n: resu...
[n, m] = [int(x) for x in input().split()] A = [] counter = 0 while counter < n: A.append([int(x) for x in input().split()]) counter += 1 B = [int(input()) for j in range(m)] counter = 0 while counter < n: result = 0 for j in range(m): result += A[counter][j] * B[j] print(r...
p02410
(n, m) = [int(i) for i in input().split()] A = [] b = [] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(eval(input()))) for i in range(n): s = 0 for j in range(m): s += A[i][j] * b[j] print(s)
n, m = [int(i) for i in input().split()] matrix = [] for ni in range(n): matrix.append([int(a) for a in input().split()]) vector = [] for mi in range(m): vector.append(int(eval(input()))) for ni in range(n): sum = 0 for mi in range(m): sum += matrix[ni][mi] * vector[mi] pr...
p02410
n,m = list(map(int,input().split())) A = [[0 for q in range(m)] for w in range(n)] B = [0 for e in range(m)] for i in range(n): A[i] = list(map(int, input().split())) for j in range(m): B[j] = int(eval(input())) for i in range(n): c = 0 for j in range(m): c += A[i][j] * B[j] print(c)
listA = [] listB = [] Answer = [] n, m = list(map(int, input().split())) for i in range(n): listA.append(list(map(int, input().split()))) for j in range(m): listB.append(int(eval(input()))) for k in range(n): result = 0 for l in range(m): result += listA[k][l]*listB[l] Answer.app...
p02410
n,m = list(map(int,input().split())) A = [] b = [] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(eval(input()))) for i in range(n): sum = 0 for j in range(m): sum += A[i][j]*b[j] print(sum)
n,m=list(map(int,input().split())) A =[[int(i) for i in input().split()] for j in range(n)] b = [] for i in range(m): b.append(int(eval(input()))) ans = [0 for i in range(n)] for i in range(n): for j in range(m): ans[i] += A[i][j]*b[j] for i in ans: print(i)
p02410
n,m = list(map(int, input().split())) # init A = [] b = [] for _ in range(n): A.append(list(map(int, input().split()))) for _ in range(m): b.append(int(eval(input()))) for row in range(n): p = 0 for i, j in zip(A[row], b): p += i * j print(p)
n, m = list(map(int, input().split())) A = [] for i in range(n): A.append(list(map(int, input().split()))) b = [] for i in range(m): b.append(int(eval(input()))) for i in range(n): sum = 0 for j in range(m): sum += A[i][j] * b[j] print(sum)
p02410
n, m = list(map(int, input().split())) a = [[int(i) for i in input().split()] for j in range(n)] b = [int(eval(input())) for i in range(m)] c = [0 for i in range(n)] for i in range(n): for j in range(m): c[i] += a[i][j] * b[j] for i in range(n): print((c[i]))
n, m = list(map(int, input().split())) A = [[int(e) for e in input().split()] for i in range(n)] b = [] for i in range(m): e = int(eval(input())) b.append(e) for i in range(n): p = 0 for j in range(m): p += A[i][j] * b[j] print(p)
p02410
def f():return list(map(int,input().split())) n,m = f() A = [f() for _ in [0]*n] B = [eval(input()) for _ in [0]*m] for i in range(n): print(sum([A[i][j]*B[j] for j in range(m)]))
def f():return list(map(int,input().split())) n,m = f() A = [f() for _ in [0]*n] B = [int(input()) for _ in [0]*m] for i in range(n): print(sum([A[i][j]*B[j] for j in range(m)]))
p02410
# -*- coding: utf-8 -*- """ Created on Tue Jun 20 20:19:33 2017 @author: syaga """ if __name__ == "__main__": n, q = list(map(int, input().split())) a = [] for i in range(n): b = input().split() b[1] = int(b[1]) a.append(b) ans = [] time = 0 flag = 0 ...
# -*- coding: utf-8 -*- """ Created on Tue Jun 20 20:19:33 2017 @author: syaga """ if __name__ == "__main__": n, q = list(map(int, input().split())) a = [] for i in range(n): b = input().split() b[1] = int(b[1]) a.append(b) ans = [] time = 0 while len(a)...
p02264
import sys from collections import deque s=sys.stdin.readlines() q=int(s[0].split()[1]) f=lambda x,y:(x,int(y)) d=deque(f(*e.split())for e in s[1:]) t,a=0,[] while d: k,v=d.popleft() if v>q:v-=q;t+=q;d.append([k,v]) else:t+=v;a+=[f'{k} {t}'] print(*a,sep='\n')
import sys from collections import deque s=sys.stdin.readlines() q=int(s[0].split()[1]) f=lambda x,y:(x,int(y)) d=deque(f(*e.split())for e in s[1:]) t,a=0,[] while d: k,v=d.popleft() if v>q:v-=q;t+=q;d.append([k,v]) else:t+=v;a+=[f'{k} {t}'] print(('\n'.join(a)))
p02264
# -*- coding: utf-8 -*- """ Created on Sun Apr 29 14:42:43 2018 @author: maezawa """ def print_array(g): ans = str(g[0]) if len(g) > 1: for i in range(1,len(g)): ans += ' '+str(g[i]) print(ans) name=[] time=[] current_time = 0 n, q = list(map(int, input().split()))...
# -*- coding: utf-8 -*- """ Created on Sun Apr 29 14:42:43 2018 @author: maezawa """ def print_array(g): ans = str(g[0]) if len(g) > 1: for i in range(1,len(g)): ans += ' '+str(g[i]) print(ans) name=[] time=[] current_time = 0 n, q = list(map(int, input().split()))...
p02264
from collections import deque n, q = map(int, input().split()) f = lambda a, b: (a, int(b)) dq = deque(f(*input().split()) for _ in range(n)) cnt = 0 ans = [] while dq: s, t = dq.popleft() if t <= q: cnt += t ans.append(f"{s} {cnt}") else: cnt += q dq.append((s, ...
import sys from collections import deque readline = sys.stdin.readline n, q = map(int, input().split()) f = lambda a, b: (a, int(b)) dq = deque(f(*readline().split()) for _ in range(n)) cnt = 0 ans = [] while dq: s, t = dq.popleft() if t <= q: cnt += t ans.append(f"{s} {cnt}") e...
p02264
n, q = [ int( val ) for val in input( ).split( " " ) ] ps = [0]*n t = [0]*n for i in range( n ): ps[i], t[i] = input( ).split( " " ) output = [] qsum = 0 while t: psi = ps.pop( 0 ) ti = int( t.pop( 0 ) ) if ti <= q: qsum += ti output.append( psi+" "+str( qsum ) ) else: t.append( ti - q ) ...
n, q = [ int( val ) for val in input( ).split( " " ) ] ps = [0]*n t = [0]*n for i in range( n ): ps[i], t[i] = input( ).split( " " ) output = [] qsum = 0 while t: psi = ps.pop( 0 ) ti = int( t.pop( 0 ) ) if ti <= q: qsum += ti output.append( "".join( ( psi, " ", str( qs...
p02264
from queue import Queue n, q = [ int( val ) for val in input( ).split( " " ) ] names = Queue( ) times = Queue( ) for i in range( n ): name, time = input( ).split( " " ) names.put( name ) times.put( int( time ) ) qsum = 0 output = [] while not times.empty( ): name = names.get( ) time = times.get( )...
from queue import Queue n, q = [ int( val ) for val in input( ).split( " " ) ] processes = Queue( ) for i in range( n ): name, time = input( ).split( " " ) processes.put( ( name, int( time ) ) ) qsum = 0 output = [] while not processes.empty( ): process = processes.get( ) if process[1] ...
p02264
from queue import Queue n, q = [ int( val ) for val in input( ).split( " " ) ] processes = Queue( ) for i in range( n ): name, time = input( ).split( " " ) processes.put( ( name, int( time ) ) ) qsum = 0 output = [] while not processes.empty( ): process = processes.get( ) if process[1] ...
from collections import deque n, q = [ int( val ) for val in input( ).split( " " ) ] processes = deque( ) for i in range( n ): name, time = input( ).split( " " ) processes.append( ( name, int( time ) ) ) qsum = 0 output = [] while len( processes ): process = processes.popleft( ) if proce...
p02264
n,q = list(map(int, input().split())) que = [list(map(str, input().split())) for i in range(n)] for i in range(n):que[i][1] = int(que[i][1]) mxt = sum([y for x,y in que]) t = 0 i = 0 while t < mxt: i %= n a = que[i] if 0 < a[1] <= q: t += a[1] que[i][1] = 0 print(a[0],t) elif q < a[1]: t +...
n,q = list(map(int, input().split())) que = [list(map(str, input().split())) for i in range(n)] for i in range(n):que[i][1] = int(que[i][1]) mxt = sum([y for x,y in que]) t = 0 i = 0 while t < mxt: i %= n a = que[i] if 0 < a[1] <= q: t += a[1] que.pop(i) n -= 1 print(a[0],t) elif q < a[1]:...
p02264
# -*- coding: utf-8 -*- dict={} kl=[] n,p=list(map(int,input().split())) for i in range(n): key,value=input().split() kl.append(key) dict.update({key:int(value)}) cnt=0 time=0 count=0 while time!=n: for key in kl: if 0<dict[key]<=p: cnt+=dict[key] dict...
# -*- coding: utf-8 -*- dict={} kl=[] n,p=list(map(int,input().split())) for i in range(n): key,value=input().split() kl.append(key) dict.update({key:int(value)}) cnt=0 time=0 while time!=n: for key in kl[:]: if 0<dict[key]<=p: cnt+=dict[key] dict[key]=...
p02264
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp #?????\??? #??????????????¨????§?????????¨?????¨????????????????????????????????????????????????????????? def rrs(quantum, process): finished_process = [] time_queue = Queue() name_queue = Queue() current_time = 0...
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp #?????\??? #??????????????¨????§?????????¨?????¨????????????????????????????????????????????????????????? def rrs(quantum, process): finished_process = [] queue = Queue() current_time = 0 for p in process: queue...
p02264
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp #?????\??? #??????????????¨????§?????????¨?????¨????????????????????????????????????????????????????????? def rrs(quantum, process): finished_process = [] queue = Queue() current_time = 0 for p in process: queue...
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp #?????\??? #??????????????¨????§?????????¨?????¨????????????????????????????????????????????????????????? def rrs(quantum, process): finished_process = [] queue = Queue() current_time = 0 i = 0 while len(finished_pro...
p02264
from collections import deque n, q = list(map(int,input().split())) queue = deque([]) for i in range(n): queue.append(list(map(str,input().split()))) queue = deque([[x[0],int(x[1])] for x in queue]) end = deque([]) time = 0 while len(queue) > 0: xqt = queue.popleft() res_time = xqt[1] - q ...
from collections import deque n, q = list(map(int,input().split())) queue = deque([]) for i in range(n): queue.append(list(map(str,input().split()))) queue = deque([[x[0],int(x[1])] for x in queue]) time = 0 while len(queue) > 0: xqt = queue.popleft() res_time = xqt[1] - q if res_time <...
p02264
import sys def isEmpty(S): if len(S) == 0: return True def isFull(S): if len(S) >= 100000: return True def enqueue(x): if isFull(x_list_list): print('Error') x_list_list.append(x) def dequeue(x_list_list): if isEmpty(x_list_list): print('Error') del_list = x_list_list[0...
import sys def isEmpty(S): if len(S) == 0: return True def isFull(S): if len(S) >= 100000: return True def enqueue(x): if isFull(x_list_list): print('Error') x_list_list.append(x) def dequeue(x_list_list): if isEmpty(x_list_list): print('Error') del_list = x_list_list[0...
p02264
class Queue(object): def __init__(self, _max): if type(_max) != int: raise ValueError self._array = [None for i in range(0, _max)] self._head = 0 self._tail = 0 self._cnt = 0 def enqueue(self, value): if self.is_full(): raise In...
class Queue(object): def __init__(self, _max): if type(_max) != int: raise ValueError self._array = [None for i in range(0, _max)] self._head = 0 self._tail = 0 self._cnt = 0 def enqueue(self, value): if self.is_full(): raise In...
p02264
class Process(object): def __init__(self, name, s): self.name = name self.s = s def exec(self, q): if self.s <= q: time = self.s self.s = 0 return time else: time = q self.s = self.s - q return ...
class Process(object): def __init__(self, name, s): self.name = name self.s = s def exec(self, q): if self.s <= q: time = self.s self.s = 0 return time else: time = q self.s = self.s - q return ...
p02264
def search(N, M, adj): reachable = [[set() for i in range(N)] for _ in range(N)] reachable[0] = adj start = -1 for m in range(1, N): prev = reachable[m-1] cur = reachable[m] for i in range(N): cur[i] = set(prev[i]) for i in range(N): for ...
def search(N, M, adj): reachable = [[set() for i in range(N)] for _ in range(N)] reachable[0] = adj start = -1 for m in range(1, N): prev = reachable[m-1] cur = reachable[m] # for i in range(N): # cur[i] = set(prev[i]) for i in range(N):...
p02902
import sys input = sys.stdin.readline def main(): n,m = list(map(int,input().split())) edge = [[] for _ in [0]*n] for _ in range(m): a,b = list(map(int,input().split())) edge[a-1].append(b-1) new = [tuple([i]) for i in range(n)] res = [] tank = [] res2 = -1 ...
import sys input = sys.stdin.readline def main(): n,m = list(map(int,input().split())) edge = [[] for _ in [0]*n] for _ in range(m): a,b = list(map(int,input().split())) edge[a-1].append(b-1) new = [0]*n for i in range(n): new[i] = [i] res = [] tank = ...
p02902
from collections import deque def dfs(N, AB): status = [-1] * N for i in range(N): if status[i] == 1: continue stack = [i] status[i] = 0 while stack: v = stack[-1] if AB[v]: n = AB[v].popleft() ...
def dfs(N, AB): status = [-1] * N for i in range(N): if status[i] == 1: continue stack = [i] status[i] = 0 while stack: v = stack[-1] if AB[v]: n = AB[v].pop() if status[n] == -1: ...
p02902
from collections import deque n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) edges[a - 1].append(b - 1) def bfs(node): seen = [0] * n todo = deque([]) for to in edges[node]: todo.append([to, ...
n, m = list(map(int, input().split())) edges = [[] for _ in range(n)] for _ in range(m): a, b = list(map(int, input().split())) edges[a-1].append(b-1) def get_first_cycle(n, edges): seen = [-1] * n # seen: -1: 未確認, 0: 非cycleのnode, 1: cycle候補 for start in range(n): if seen[start] =...
p02902
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,m = list(map(int, input().split())) from collections import defaultdict ns = defaultdict(set) for i in range(m): a,b = list(map(int, input().split())) ns[...
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,m = list(map(int, input().split())) from collections import defaultdict ns = defaultdict(set) for i in range(m): a,b = list(map(int, input().split())) ns[...
p02902
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,m = list(map(int, input().split())) from collections import defaultdict ns = defaultdict(set) for i in range(m): a,b = list(map(int, input().split())) ns[...
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") from collections import defaultdict n,m = list(map(int, input().split())) ns = defaultdict(set) es = set() for _ in range(m): u,v = list(map(int, input().split())...
p02902
def dfs(N, AB): status = [-1] * N for i in range(N): if status[i] == 1: continue stack = [i] status[i] = 0 while stack: print(("stack:", stack)) v = stack[-1] if AB[v]: n = AB[v].pop() if status[n] == -1: ...
def find_cycle(N, AB): for c in range(N): stack = [(c, [])] while stack: # print("stack:", stack) curr, visited = stack.pop() if curr in visited: # print("cycle found:", curr) return visited else: # print("adding in visited:", curr) for i in A...
p02902
import sys from collections import deque from collections import defaultdict import copy n, m = list(map(int, sys.stdin.readline().split())) adj = [[] for _ in range(n+1)] for _ in range(m): a, b = list(map(int, sys.stdin.readline().split())) adj[a].append(b) def searchRoute(i): global adj ...
import sys from collections import deque from collections import defaultdict import copy n, m = list(map(int, sys.stdin.readline().split())) adj = [[] for _ in range(n+1)] radj = [[] for _ in range(n+1)] for _ in range(m): a, b = list(map(int, sys.stdin.readline().split())) adj[a].append(b) radj...
p02902
def examA(): class Dijkstra(object): """ construct: O(ElogV) """ def __init__(self, edges, start=0): """ :param list of list of list of int edges: :param int start=0: """ self.__dist = [inf] * len(edges) ...
def examA(): class Dijkstra(object): """ construct: O(ElogV) """ def __init__(self, edges, start=0): """ :param list of list of list of int edges: :param int start=0: """ self.__dist = [inf] * len(edges) ...
p02902
# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline from collections import deque def bfs(g,root,memo,backtrack): q = deque() # """初期化、キューに入れて訪問済みにする""" memo[root] = 0 q.append(root) """BFS""" while q: #キューが空になるまで v =...
# find a cycle def find_cycle(g): n = len(g) used = [0]*n #0:not yet 1: visiting 2: visited for v in range(n): #各点でDFS if used[v] == 2: continue #初期化 stack = [v] hist =[] #履歴 while stack: v = stack[-1] if used[v] == 1: ...
p02902
import sys from collections import deque sys.setrecursionlimit(10**9) input = lambda: sys.stdin.readline().rstrip() inpl = lambda: list(map(int,input().split())) N, M = inpl() uv = [ set() for _ in range(N)] vu = [ set() for _ in range(N)] for _ in range(M): A, B = inpl() uv[A-1].add(B-1) vu[B-1]...
import sys input = lambda: sys.stdin.readline().rstrip() inpl = lambda: list(map(int,input().split())) N, M = inpl() uv = [ set() for _ in range(N)] vu = [ set() for _ in range(N)] for _ in range(M): A, B = inpl() uv[A-1].add(B-1) vu[B-1].add(A-1) EMPTY, LOOP, TREE = 0, 1, 2 ENTER, EXIT = 0, 1 ...
p02902
from collections import defaultdict from heapq import heappop, heappush class Graph(object): """ 隣接リストによる有向グラフ """ def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, src, dst, weight=1): sel...
from collections import defaultdict from heapq import heappop, heappush class Graph(object): """ 隣接リストによる有向グラフ """ def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, src, dst, weight=1): sel...
p02902
import collections as c n,k=list(map(int,input().split()));a=c.Counter(list(map(int,input().split()))) print(([0,sum(sorted([i for i in list(a.values())])[:len(a)-k])][len(a)>k]))
import collections as c n,k=list(map(int,input().split()));a=c.Counter(list(map(int,input().split()))) print(([0,sum(sorted([*list(a.values())])[:len(a)-k])][len(a)>k]))
p03495
n, k = (int(i) for i in input().split()) balls = list(int(i) for i in input().split()) ball_set = set(balls) freqs = list(balls.count(i) for i in ball_set) freqs.sort(reverse=True) print((sum(freqs[k:])))
n, k = (int(i) for i in input().split()) balls = (int(i) for i in input().split()) freqs = {} for ball in balls: freqs[ball] = freqs[ball] + 1 if ball in freqs else 1 freq_hist = list(freqs.values()) freq_hist.sort(reverse=True) print((sum(freq_hist[k:])))
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) from collections import Counter c = Counter(a) key = [] value = [] for i, j in sorted(list(c.items()), key=lambda x: x[1]): key.append(i) value.append(j) print((sum(value[:(len(key)-k)])))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) from collections import Counter c = Counter(a) cnts = [] for i, j in list(c.items()): cnts.append(j) print((sum(sorted(cnts)[:-k])))
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) from collections import Counter c = Counter(a) cnts = [] for i, j in list(c.items()): cnts.append(j) print((sum(sorted(cnts)[:-k])))
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts)[:-k])))
p03495
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts)[:-k])))
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnts = list(Counter(a).values()) print((sum(sorted(cnts, reverse=True)[k:])))
p03495
#!/usr/bin/env python3 import sys import collections def solve(N: int, K: int, A: "List[int]"): a_counter = collections.Counter(A) if len(a_counter) <= K: print((0)) return values = sorted(list(a_counter.values())) answer = 0 for i in range(len(a_counter)-K): ...
#!/usr/bin/env python3 import sys from collections import Counter def solve(N: int, K: int, A: "List[int]"): counter = list(Counter(A).values()) counter.sort() if len(counter) <= K: print((0)) else: need = len(counter)-K print((sum(counter[:need]))) return ...
p03495
from collections import Counter N,K=list(map(int,input().split())) a = list(map(int,input().split())) d=Counter(a) d=sorted(list(d.items()),key=lambda x:x[1]) ans=0 for i in range(len(d)-K): ans+=d[i][1] print(ans)
from collections import Counter N,K=list(map(int,input().split())) a = list(map(int,input().split())) d=Counter(a) ans=sum(sorted(list(d.values()),reverse=1)[:K]) print((N-ans))
p03495
n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() kind=[] count=1 for i in range(len(a)-1): if(a[i]==a[i+1]):count+=1 else: kind.append(count) count=1 kind.append(count) kind.sort() change=0 while(len(kind)>k): change+=kind.pop(0) print(change)
n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() kind=[] count=1 for i in range(len(a)-1): if(a[i]==a[i+1]):count+=1 else: kind.append(count) count=1 kind.append(count) kind.sort() change=0 for i in range(k): if(len(kind)!=0):change+=kind.pop() print((n-change))
p03495
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) ans=0 c=collections.Counter(a) if len(c)<k: print(ans) exit() for i in range(1,-k+len(c)+1): ans+=c.most_common()[-i][1] print(ans)
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) ans=0 c=collections.Counter(a) if len(c)<k: print(ans) exit() l=c.most_common() for i in range(1,-k+len(c)+1): ans+=l[-i][1] print(ans)
p03495
nums , types = list(map(int, input().split())) array = list(map(int,input().split())) array.sort() type_count = 0 count = 0 result = 0 ary_count = [] array.append(1000000000) for i in range (nums): if array[i] == array[i +1]: count += 1 elif array[i] < array[i +1]: ary_count.append...
nums , types = list(map(int, input().split())) array = list(map(int,input().split())) array.sort() type_count = 0 count = 0 result = 0 ary_count = [] array.append(1000000000) for i in range (nums): if array[i] == array[i +1]: count += 1 elif array[i] < array[i +1]: ary_count.append...
p03495
from collections import Counter N,K=list(map(int,input().split())) A=input().split() B=Counter(A) C=sorted(list(B.items()),key=lambda x: -x[1]) print((sum(C[K:][i][1] for i in range(len(C[K:])))))
from collections import Counter N,K=list(map(int,input().split())) A=input().split() B=Counter(A) C=sorted(list(B.values()),reverse=True) print((sum(C[K:])))
p03495
from collections import Counter n,k = list(map(int,input().split())) dic = Counter(list(map(int,input().split()))) x = len(dic) - k lis = sorted(list(dic.items()), key = lambda z:z[1]) ans = 0 for i in range(x): ans += lis[i][1] print(ans)
from collections import Counter from operator import itemgetter n,k = list(map(int,input().split())) dic = Counter(list(map(int,input().split()))) x = len(dic) - k lis = sorted(list(dic.items()), key = itemgetter(1)) ans = 0 for i in range(x): ans += lis[i][1] print(ans)
p03495
N,K=list(map(int,input().split())) s=list(map(int,input().split())) t=list(set(s)) ss,ans=[],0 for i in t: ss.append(s.count(i)) ss=sorted(ss) if len(ss)>K: for i in range(len(ss)-K): ans+=ss[i] print(ans) else: print("0")
N,K=list(map(int,input().split())) d,ans={},0 for i in list(map(int,input().split())): d[i]=d.get(i,0)+1 s=sorted(d.values()) for i in range(len(s)-K): ans+=s[i] print(ans)
p03495
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) c = Counter(A).most_common() c.sort(key=lambda x: -x[1]) ans = 0 while len(c) > K: ans += c.pop()[1] print(ans)
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) print((sum(sorted(Counter(A).values())[:-K])))
p03495
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) cnt = Counter() for num in A: cnt[str(num)] += 1 values = sorted(cnt.values()) ans = 0 for x in range(len(values) - K): ans += values.pop(0) print(ans)
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) cnt = Counter() for num in A: cnt[str(num)] += 1 values = sorted(cnt.values()) ans = sum(values[:max(len(values)-K, 0)]) print(ans)
p03495
from collections import Counter N,K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] counter = Counter(A) ans = 0 counter_list = counter.most_common() if K < len(counter_list): while (K!=len(counter_list)): ans += counter_list[-1][1] counter_list = counter_list[:-1...
from collections import Counter N,K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] counter = Counter(A) ans = 0 counter_list = counter.most_common()[::-1] if K < len(counter_list): for a in counter_list[:len(counter_list)-K]: ans += a[1] print(ans)
p03495
N,K = list(map(int, input().split(' '))) A = input().split(' ') num = [] count = [] for a in range(len(A)): tmp = A[a] if not tmp in num: num.append(tmp) count.append(1) else: index = num.index(tmp) count[index] += 1 count = sorted(count) ans = 0 if len(coun...
#辞書型でリトライ N,K = list(map(int, input().split(' '))) A = input().split(' ') dic = {} for a in range(len(A)): tmp = A[a] if not tmp in dic: dic[tmp] = 1 else: dic[tmp] += 1 values = sorted(dic.values()) ans = 0 if len(values)<=K: pass else: tmp = len(values)-K va...
p03495
# coding: utf-8 # https://atcoder.jp/contests/abc081/tasks/arc086_a # 14:07-14:14 done def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = sorted(A) cnt = {} for a in A: if a in cnt: cnt[a] += 1 else: ...
# coding: utf-8 # https://atcoder.jp/contests/abc081/tasks/arc086_a # 14:07-14:14 done def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = sorted(A) cnt = {} for a in A: if a in cnt: cnt[a] += 1 else: ...
p03495
from collections import Counter _, K = list(map(int, input().split())) A = list(map(int, input().split())) _, cnt = list(zip(*Counter(A).most_common()[::-1])) print((sum(cnt[:len(cnt) - K])))
from collections import Counter _, K = list(map(int, input().split())) A = sorted(list(Counter(input().split()).values())) print((sum(A[:len(A)-K])))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) from collections import Counter c = Counter(A) cnt = 0 if len(c) > K: for i in range(K, len(c)): cnt += c.most_common()[i][1] print(cnt)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) from collections import Counter ac = Counter(A) cnt = 0 if len(ac) > K: for a in ac.most_common()[K:]: cnt += a[1] print(cnt)
p03495
from collections import Counter n, k = list(map(int,input().split())) a = list(map(int,input().split())) c = Counter(a) l = len(c) cnt = 0 if k < l: i = -1 for _ in range(l-k): cnt += c.most_common()[i][1] i -= 1 print(cnt)
from collections import Counter import heapq n, k = list(map(int,input().split())) a = list(map(int,input().split())) c = Counter(a) heapc = list(c.values()) heapq.heapify(heapc) l = len(c) cnt = 0 if k < l: for _ in range(l-k): cnt += heapq.heappop(heapc) print(cnt)
p03495
N, K = (int(x) for x in input().split()) A = [int(x) for x in input().split()] cnt = [A.count(a) for a in set(A)] cnt.sort() vrt = len(cnt) print((sum(cnt[:vrt-K]) if vrt > K else 0))
import bisect as bs N, K = (int(x) for x in input().split()) A = sorted([int(x) for x in input().split()]) f = lambda X, x: bs.bisect_right(X,x)-bs.bisect_left(X,x) cnt = sorted([f(A,a) for a in set(A)],reverse=True) vrt = len(cnt) print((sum(cnt[K:]) if vrt > K else 0))
p03495
# ABC081C - Not so Diverse (ARC086C) from collections import Counter def main(): N, K, *A = list(map(int, open(0).read().split())) C = list(Counter(A).values()) C.sort(reverse=1) ans = sum(C[K:]) print(ans) if __name__ == "__main__": main()
# ABC081C - Not so Diverse (ARC086C) from collections import Counter def main(): N, K, *A = open(0).read().split() C, K = list(Counter(A).values()), int(K) C.sort(reverse=1) ans = sum(C[K:]) print(ans) if __name__ == "__main__": main()
p03495
from collections import defaultdict N, K = list(map(int, input().split())) A = list(map(int, input().split())) d = defaultdict(int) for i in range(N): d[A[i]] += 1 cnt = len(list(d.keys())) - K d = sorted(list(d.items()), key=lambda x:x[1]) ans = 0 for val in d: if cnt <= 0: print(ans) exi...
from collections import defaultdict N, K = list(map(int, input().split())) A = list(map(int, input().split())) d = defaultdict(int) for i in range(N): d[A[i]] += 1 cnt = max(len(list(d.keys())) - K, 0) d = sorted(list(d.items()), key=lambda x:x[1]) ans = 0 for i in range(cnt): ans += d[i][1] print(...
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) dict = {} for Ai in A: if Ai in dict: dict[Ai] += 1 else: dict[Ai] = 1 count = 0 while len(dict) > K: max_key = max(dict, key=dict.get) min_key = min(dict, key=dict.get) dict[max_key] += 1 dic...
N, K = list(map(int, input().split())) A = list(map(int, input().split())) dict = {} for Ai in A: if Ai in dict: dict[Ai] += 1 else: dict[Ai] = 1 count = 0 if len(dict) > K: count = sum(sorted(dict.values())[:len(dict) - K]) print(count)
p03495
from collections import Counter n, k = list(map(int, input().split())) a = Counter((i for i in input().split())) sort_count = sorted(list(a.items()), key=lambda x: x[1]) total = 0 while len(sort_count) > k: _, n = sort_count.pop(0) total += n print(total)
N, K = list(map(int, input().split())) B = [0]*(N+1) for i in input().split(): B[int(i)] += 1 print((sum(sorted(B)[:-K])))
p03495
from collections import Counter n,k=list(map(int,input().split())) a=input().split() x=len(list(set(a))) n=x-k if x-k>=0 else 0 counter=Counter(a) l=sorted(counter.values()) print((sum(l[:n])))
from collections import Counter n,k=list(map(int,input().split())) a=input().split() x=len(list(set(a))) n=x-k if x-k>=0 else 0 print((sum(sorted(Counter(a).values())[:n])))
p03495
import sys from collections import Counter input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] C = Counter(A) ans = 0 if len(C) <= K: print((0)) return else: for i in range(len(C) - K)...
import sys from collections import Counter input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] C = Counter(A) ans = 0 if len(C) <= K: print((0)) return else: mc = C.most_common() ...
p03495
n,k = list(map(int,input().split())) l = list(map(int, input().split())) def counter(l): count = {} for i in l: count[i] = l.count(i) return sorted(count.values()) freq = counter(l) vf = len(freq) - k if len(freq)> k else 0 print((sum(freq[:vf])))
n,k = list(map(int,input().split())) l = list(map(int, input().split())) freq = [0]*(n+1) for i in l: freq[i]+=1 freq.sort() vf = len(freq) - k if len(freq)> k else 0 print((sum(freq[:vf])))
p03495
from collections import Counter n,k = list(map(int,input().split())) a = list(map(int,input().split())) cnt = Counter(a) mo = cnt.most_common()[::-1] #print(mo) ans = 0 for i in range(max(0,len(mo)-k)): ans += mo[i][1] print(ans)
from collections import Counter n,k = list(map(int,input().split())) a = list(map(int,input().split())) cnt = Counter(a) mo = sorted(cnt.values()) #print(mo) ans = 0 for i in range(max(0,len(mo)-k)): ans += mo[i] print(ans)
p03495
def main(): from collections import Counter n, k, *a = list(map(int, open(0).read().split())) c = Counter(a) v = len(c) l = list(c.values()) m = sorted(l) ans = sum(m[:v - k]) print(ans) if __name__ == '__main__': main()
def main(): from collections import Counter n, k, *a = list(map(int, open(0).read().split())) c = list(Counter(a).values()) v = len(c) - k l = list(c) l.sort() ans = sum(l[:v]) print(ans) if __name__ == '__main__': main()
p03495
from collections import * f=lambda:list(map(int,input().split())) _,k=f() c=Counter(f()) print((sum(sorted(c.values())[~k::-1])))
from collections import*;f=lambda:list(map(int,input().split()));_,k=f();print((sum(sorted(Counter(f()).values())[:-k])))
p03495
import collections from collections import OrderedDict num = [int(x) for x in input().split()] val = input().split() count_dict = collections.Counter(val) cant = 0 if len(count_dict) <= num[1]: print((0)) else: sort_dict = OrderedDict(sorted(list(count_dict.items()), key=lambda x:x[1], reverse...
import collections n, k = list(map(int, input().split())) array = [int(x) for x in input().split()] _dict = collections.Counter(array) res = 0 tmp = len(list(_dict.values())) if len(list(_dict.values())) < k: print((0)) else: sort_dict = collections.OrderedDict(sorted(list(_dict.items()), key=lambd...
p03495
import collections def calc(A, K): dist = {} tmp = collections.Counter(A) type_ = len(tmp) if type_ <= K: return 0 for a, count in list(tmp.items()): if count not in list(dist.keys()): dist[count] = [a] else: dist[count].append(a) ...
N, K = list(map(int, input().split())) cnt = [0 for _ in range(N)] for i in map(int, input().split()): cnt[i-1] += 1 ans = 0 for i in sorted(cnt)[:N - K]: ans += i print(ans)
p03495
N,K=list(map(int,input().split())) A=list(map(int,input().split())) As=list(set(A)) sa=max(0,len(As)-K) if sa==0: print((0)) exit else: count=[0]*len(As) for i in range(len(As)): count[i]=int(A.count(As[i])) num=sorted(count) num2=num[0:sa] ans=0 for i in num2: ...
N,K=list(map(int,input().split())) A=list(map(int,input().split())) sa=len(set(A))-K if sa>0: As={} for i in range(N): if A[i] in As: As[A[i]]+=1 else: As[A[i]]=1 Ass=sorted(As.values()) print((sum(Ass[:sa]))) else: print((0))
p03495
a, b = list(map(int, input().split())) n = list(map(int, input().split())) m = list(set(n)) c = 0 if len(m) <= b: print((0)) else: dic = {} for i in range(len(m)): dic[str(m[i])] = n.count(m[i]) dic = sorted(list(dic.items()), key = lambda x:x[1]) for i in range(len(...
a, b = list(map(int, input().split())) n = list(map(int, input().split())) l = {} for a in n: l[a] = l.get(a, 0) + 1 print((sum(sorted(l.values())[:-b])))
p03495
from collections import Counter n, k = [int(i) for i in input().split()] a = Counter([int(i) for i in input().split()]) cost = 0 print((sum(c for (v, c) in a.most_common()[k:])))
from collections import Counter n, k = [int(i) for i in input().split()] a = Counter([int(i) for i in input().split()]) print((sum(c for (v, c) in a.most_common()[k:])))
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = {} for i in a: if i in b: b[i] += 1 else: b[i] = 1 b = sorted(b.values()) print((sum(b[:-k])))
n, k = list(map(int, input().split())) b = {} for i in input().split(): if i in b: b[i] += 1 else: b[i] = 1 b = sorted(b.values()) print((sum(b[:-k])))
p03495