input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import collections N,K = list(map(int,input().split())) A = list(map(int,input().split())) sum = 0 tmp = len(list(set(A))) li = collections.Counter(A) for i in range(K,tmp,1): sum += li.most_common()[i][1] print(sum)
import collections N,K = list(map(int,input().split())) A = list(map(int,input().split())) ans = 0 tmp = len(list(set(A))) li = collections.Counter(A) value,counts = list(zip(*li.most_common())) for i in range(K,tmp,1): ans += counts[i] print(ans)
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)
from collections import Counter n, k = list(map(int, input().split())) a = Counter((i for i in input().split())) sort_count = sorted(a.values()) total = 0 l = len(sort_count) if len(sort_count) <= k: print((0)) else: print((sum(sort_count[:l-k])))
p03495
from collections import defaultdict n, k = [int(x) for x in input().split()] a_list = [int(x) for x in input().split()] d = defaultdict(int) for a in a_list: d[a] += 1 print((sum(sorted(d.values())[:-k])))
from collections import defaultdict n, k = [int(x) for x in input().split()] a_list = [int(x) for x in input().split()] d = defaultdict(int) for a in a_list: d[a] += 1 print((sum(sorted(list(d.values()), reverse=True)[k:])))
p03495
n, k = list(map(int, input().split())) nums = list(map(int, input().split())) def judge(n, k, nums): original = nums types = set(nums) diff = len(types) - k count = [] ans = 0 if len(types) <= k: return 0 for i in types: count.append(original.count(i)) count.sort() for i in ...
n, k = list(map(int, input().split())) nums = list(map(int, input().split())) def judge(n, k, nums): original = nums types = set(nums) diff = len(types) - k count = [] temp_count = 0 temp_char = nums[0] ans = 0 nums.sort() if len(types) <= k: return 0 for i in range(n): if ...
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a = sorted(a) p = list(set(a)) if len(p) <= k: print('0') exit() j = 0 ans = [0 for _ in range(len(p))] for i in range(len(p)): ans[i] += a.count(p[i]) ans = sorted(ans) print((sum(ans[:len(p) - k])))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a = sorted(a) p = list(set(a)) if len(p) <= k: print('0') exit() j = 0 ans = [0 for _ in range(len(p))] ans[0] = 1 for i in range(1, n): if a[i] == a[i - 1]: ans[j] += 1 else: j += 1 ...
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) import collections c = collections.Counter(A) values, counts = list(zip(*c.most_common()[::-1])) counts = list(counts) cnt = 0 inf = 10 ** 18 for _ in range(inf): if len(counts) <= K: print(cnt) break cnt += co...
N, K = list(map(int, input().split())) A = list(map(int, input().split())) import collections from itertools import accumulate c = collections.Counter(A) _, counts = list(zip(*c.most_common()[::-1])) counts = list(accumulate(counts)) cnt = 0 inf = 10 ** 18 target = len(counts) - K if target <= 0: ...
p03495
n,k = list(map(int,input().split())) a = list(map(int,input().split())) s = set(a) r = [] for i in s: r.append(a.count(i)) r = sorted(r) dif = len(s) - k print((sum(r[0:max(0,dif)])))
import itertools n,k = list(map(int,input().split())) a = sorted(list(map(int,input().split()))) c = [] g = itertools.groupby(a) for m,v in g: c.append(len(list(v))) c = sorted(c) print((sum(c[:-k])))
p03495
N, K = [int(i) for i in input().split()] B = sorted([int(i) for i in input().split()]) D ={} bag = 0 for i in B: if i in D: D[i] += 1 else: D[i] = 1 LLL = sorted(list(D.values())) AA = len(D) - K if len(D) <= K: print((0)) else: for i in range(AA): bag += LLL[i...
N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] dic = {} for i in A: if i in dic: dic[i] += 1 else: dic[i] = 1 dic_sort = sorted(list(dic.items()), key=lambda x:x[1], reverse=True) ans = [] for i in range(K, len(dic_sort)): ans.append(dic_sort[...
p03495
from collections import Counter from collections import defaultdict N, K = list(map(int, input().split())) A = list(map(int, input().split())) B = Counter(A).most_common() dict = [] for l in B: dict.append([l[0], l[1]]) dict.sort(key=lambda x:x[1]) count = 0 l = len(B) if l <= K: print((0)) else: ...
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) ca = Counter(A) ca = sorted(list(ca.items()), key=lambda x:x[1], reverse=True) ans = 0 for i in range(min(K, len(ca))): ans += ca[i][1] print((N-ans))
p03495
import sys import collections if sys.platform =='ios': sys.stdin=open('Untitled.txt') N, K = [int(x) for x in input().split()] nums = [int(x) for x in input().split()] count = 0 while len(set(nums)) > K: c = collections.Counter(nums) ma = c.most_common()[0] mi = c.most_common()[-1] nums = [ma[0]...
import sys import collections if sys.platform =='ios': sys.stdin=open('Untitled.txt') N, K = [int(x) for x in input().split()] nums = [int(x) for x in input().split()] c = collections.Counter(nums) d = c.most_common()[::-1] print((sum([d[i][1] for i in range(len(d) - K)])))
p03495
N,K=[int(i) for i in input().split()] A=[int(i) for i in input().split()] s=[0 for i in range(200000)] for i in range(200000): t=A.count(i) s[i]+=t s.sort() s.reverse() p=0 for i in range(K): p+=s[i] print((N-p))
s=0 R=[] N,K=[int(i) for i in input().split()] A=[int(i) for i in input().split()] import collections c=collections.Counter(A).most_common() # for i in c.values(): # R.append(i) if len(c)>K: for i in range(K): s+=c[i][1] print((N-s)) else: print("0")
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) dic = {} for num in a: if num not in list(dic.keys()): dic[num] = 0 dic[num] += 1 dic = sorted(list(dic.items()), key=lambda x:x[1]) ans = 0 for i in range(len(dic)- k): ans += dic[i][1] print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = [0] * n for i in range(n): b[a[i] - 1] += 1 b.sort(reverse=True) ans = 0 for i in range(k): ans +=b[i] if n - ans <= 0: print((0)) else: print((n - ans))
p03495
from collections import Counter n,k = list(map(int,input().split())) n_lst = list(map(int,input().split())) cnt_lst = Counter(n_lst).most_common()[k:] ans = 0 for x in cnt_lst: ans += x[1] print(ans)
n,k = list(map(int,input().split())) n_lst = list(map(int,input().split())) cnt_lst = [0 for _ in range(n+1)] for x in n_lst: cnt_lst[x] += 1 cnt_lst.sort(reverse=True) print((sum(cnt_lst[k:])))
p03495
import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = dict(collections.Counter(A)) cnt = 0 for i in range(N): if len(A) > K: min_k = min(A, key=A.get) cnt += A[min_k] A.pop(min_k) else: break print(cnt)
import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) A = dict(collections.Counter(A)) A = sorted(list(A.items()), key=lambda x: x[1], reverse=True) cnt = 0 for i in range(N): if len(A) > K: cnt += A[-1][1] A.pop() else: break p...
p03495
import sys from math import sqrt from collections import Counter input = sys.stdin.readline def I(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) inf = float("inf") mod = 10 ** 9 + 7 def main(): n, k = MI() a_list = MI() ...
import sys from math import sqrt from collections import Counter input = sys.stdin.readline def I(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) inf = float("inf") mod = 10 ** 9 + 7 def main(): n, k = MI() a_list = MI() ...
p03495
N,K = list(map(int,input().split())) A = list(map(int,input().split())) D = {} for i in range(N) : if A[i] not in D : D[A[i]] = 1 else : D[A[i]] += 1 L = list(D.values()) L = sorted(L) ans = 0 for i in range(len(L)) : if len(L) > K : ans += L[0] L.pop(0) print(...
N,K = list(map(int,input().split())) A = list(map(int,input().split())) D = {} for i in A : if i in D : D[i] += 1 else : D[i] = 1 D = sorted(list(D.items()),key=lambda x:x[1]) counter = 0 answer = 0 for j in range(len(D)) : if len(D) - counter > K : counter += 1 ...
p03495
N, K = [int(nk) for nk in input().split()] A = [int(a) for a in input().split()] A_set = list(set(A)) if len(A_set) <= K: print((0)) else: AA = [A.count(i) for i in A_set] AA.sort() ans = sum(AA[:-K]) print(ans)
N, K = [int(nk) for nk in input().split()] A = [int(a) for a in input().split()] A_set = list(set(A)) if len(A_set) <= K: print((0)) else: # len(A_set) > K: dictionary = {} for n in A_set: dictionary[n] = 0 for m in A: dictionary[m] += 1 dict_val = list(dictionary.values()) dict_va...
p03495
def 解(): iN,iK = [int(_) for _ in input().split()] aA = [int(_) for _ in input().split()] dA = {} def addD(d,a): if a in d: d[a] += 1 else: d[a] = 1 for a in aA: addD(dA,a) aList = sorted(list(dA.items()),key=lambda x:x[1]) print((s...
def 解(): iN,iK = [int(_) for _ in input().split()] #aA = [int(_) for _ in input().split()] dA = {} def addD(d,a): if a in d: d[a] += 1 else: d[a] = 1 for a in [int(_) for _ in input().split()]: addD(dA,a) aList = sorted(list(dA.items()),...
p03495
N,K = list(map(int,input().split())) balls = [] bucket = [0]*(N+1) balls = list(map(int,input().split())) balls.sort() for ball_number in balls: bucket[ball_number] += 1 def judge(number_of_types, types): if number_of_types <= types: return True number_of_types = 0 for i in bucket: ...
N,K=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() bucket=[0*i for i in range(N+1)] count=1 types=1 for i in range(1,N): if A[i]==A[i-1]: if i!=N-1: count+=1 else: count+=1 bucket[count]+=1 break else: ...
p03495
N, K = list(map(int,input().split())) A = list(map(int,input().split())) d = {} for a in A: if(a not in d): d[a] = 1 else: d[a] += 1 print((sum(sorted(d.values())[:-K])))
N, K = list(map(int,input().split())) A = list(map(int,input().split())) d = {} for a in A: if(a in d): d[a] += 1 else: d[a] = 1 print((sum(sorted(d.values())[:-K])))
p03495
n, k = list(map(int,input().split())) a = list(map(int,input().split())) d = [] c = [] for i in range(n): if not a[i] in d: d.append(a[i]) c.append(a.count(a[i])) c.sort(reverse=True) print((n-sum(c[0:k])))
n, k = list(map(int,input().split())) a = list(map(int,input().split())) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 c = sorted(list(d.items()),key = lambda x:x[1], reverse=True) ans = 0 for i in range(min(k,len(c))): ans += c[i][1] print((n-ans))
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) from collections import Counter, OrderedDict c = Counter(a) d = OrderedDict(sorted(list(c.items()), key=lambda x: x[1])) if len(d) <= k: print((0)) else: ans = 0 while len(d) > k: item = list(d.items())[0] ...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) from collections import Counter c = Counter(a) d = c.most_common() if len(d) <= k: print((0)) else: ans = 0 while len(d) > k: item = d.pop() ans += item[1] print(ans)
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt_list = [] cnt_dict = {} for i in a: if i in cnt_dict: cnt_dict[i] += 1 else: cnt_dict[i] = 1 cnt_dict_sorted = sorted(list(cnt_dict.items()), key=lambda x: x[1]) for i in set(a): cnt_list.append(a.count...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt_dict = {} for i in a: if i in cnt_dict: cnt_dict[i] += 1 else: cnt_dict[i] = 1 cnt_dict_sorted = sorted(list(cnt_dict.items()), key=lambda x: x[1]) ans = 0 if len(cnt_dict_sorted) <= k: ans = 0 else: ...
p03495
n,k=list(map(int,input().split())) a=list(map(int,input().split())) if len(list(set(a)))<=k: print((0)) else: l=[0]*n for i in range(n): l[a[i]-1]+=1 l.sort() ans=0 cnt=0 i=0 while cnt<(len(list(set(a)))-k): if l[i]!=0: ans+=l[i] cnt+=1 i+=1 else: i+...
n,k=list(map(int,input().split())) a=list(map(int,input().split())) if len(list(set(a)))<=k: print((0)) else: d={} for i in range(n): if a[i] in d: d[a[i]]+=1 else: d[a[i]]=1 d=sorted(list(d.items()),key=lambda x:x[1]) m=len(d) cnt=0 for i in range((len(list(set(a))))-k):...
p03495
from collections import Counter n,k=list(map(int,input().split())) A=list(map(int,input().split())) s=len(set(A)) C=Counter(A) if s>k: for i in range(k): n-=C.most_common()[i][1] print(n) else: print((0))
n,k=list(map(int,input().split())) A=list(map(int,input().split())) d={} for a in A: if a in d: d[a]+=1 else: d[a]=1 D=sorted(list(d.items()), key=lambda x:x[1], reverse=True) if len(set(A))>k: for i in range(k): n-=D[i][1] print(n) else: print((0))
p03495
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) L = [] B = set(A) for i in B: L.append(A.count(i)) L.sort() if len(B) <= K: print('0') else: print((...
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) B = set(A) L = [0 for i in range(N+1)] for i in A: L[i] += 1 L.sort() if len(B) <= K: print('0') else: ...
p03495
from collections import Counter n,k=list(map(int,input().split())) a=Counter(list(map(int,input().split()))) cnt=0 ls=[] if len(a)>k: for i in range(len(a)): ls.append(a.most_common()[i][1]) print((sum(ls[k:])))
n,k=list(map(int,input().split())) a=list(map(int,input().split())) d={} for i in a: d[i]=d.get(i,0)+1 s=sorted(d.values()) print((sum(s[:len(s)-k]))) # x
p03495
from collections import Counter N,K = list(map(int, input().split())) A = Counter(list(map(int, input().split()))) B = list(A.items()) k = len(B) - K if k <= 0: print((0)) else: print((sum([sorted(B,key=lambda x:x[1])[i][1] for i in range(k)])))
from collections import Counter N,K = list(map(int, input().split())) A = Counter(list(map(int, input().split()))) B = list(A.values()) k = len(B) - K if k <= 0: print((0)) else: print((sum(sorted(B)[0:k])))
p03495
from collections import Counter N,K = list(map(int, input().split())) A = Counter(list(map(int, input().split()))) B = list(A.values()) k = len(B) - K if k <= 0: print((0)) else: print((sum(sorted(B)[0:k])))
from collections import Counter N,K = list(map(int, input().split())) A = Counter(input().split()) B = list(A.values()) k = len(B) - K if k <= 0: print((0)) else: print((sum(sorted(B)[0:k])))
p03495
N,K = list(map(int,input().split(" "))) A = list(map(int,input().split(" "))) num = list(set(A)) ans=[] for n in num: ans.append(A.count(n)) print((sum(sorted(ans)[:len(ans)-K:])))
N,K = list(map(int,input().split(" "))) d={} for i in input().split(" "): if i in d: d[i]+=1 else: d[i]=1 print((sum(sorted(d.values())[:len(list(d.keys()))-K:])))
p03495
nk = list(map(int,input().split())) a = list(map(int,input().split())) sa = list(set(a)) if len(sa) > nk[1]: c = [] for i in range(len(sa)): c.append(a.count(sa[i])) sortc = sorted(c, reverse = True) m = 0 for i in range(nk[1]): m += sortc[i] ans = nk[0] - m else: ans = 0 print(ans)
nk = list(map(int,input().split())) a = list(map(int,input().split())) cli = [] for i in range(nk[0]+1): cli.append(0) for i in range(nk[0]): cli[a[i]] += 1 c = sorted(cli, reverse = True) m = 0 for i in range(nk[1]): m += c[i] ans = nk[0] - m if ans < 0: ans = 0 print(ans)
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) count = dict() for i in a: count[i] = count.get(i, 0) + 1 ans = 0 while len(count) > k: key, value = min(list(count.items()), key=lambda x : x[1]) del count[key] ans += value print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) count = {} for i in a: count[i] = count.get(i, 0) + 1 print((sum(sorted(count.values())[:-k])))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A_dict = {str(i):0 for i in set(A)} for a in A: A_dict[str(a)] += 1 del A def get_A_key_from_value(dic, value): for i, j in list(dic.items()): if j == value: break return i ans = 0 while True: if len(A_di...
#読み込み N, K = list(map(int, input().split())) A = list(map(int, input().split())) #処理回数 reduce_type = len(set(A)) - K #削除する数の選定 A_dict = {str(i):0 for i in set(A)} for a in A: A_dict[str(a)] += 1 del A list_del_num = sorted(list(A_dict.values()))[:reduce_type] #計算 ans = sum(list_del_num) print(ans)
p03495
N,K=list(map(int,input().split())) a=list(map(int,input().split())) d=[0]*N ans=0 for i in range(N): d[a[i]-1]+=1 d.sort(reverse=True) while len(d)>K: if i!=0: ans += d.pop(K) else: break print(ans)
N,K=list(map(int,input().split())) a=list(map(int,input().split())) d=[0]*N ans=0 for i in range(N): d[a[i]-1]+=1 d.sort(reverse=True) if len(d)>K: ans =sum(d[K:]) print(ans)
p03495
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in ra...
N,K = list(map(int,input().split())) A = list(map(int,input().split())) Ad = {x:0 for x in set(A)} if len(set(A)) <= K: print((0)) else: count = 0 for a in A: Ad[a] += 1 Ad = sorted(list(Ad.items()), key=lambda x:x[1]) for i in range(len(set(A))-K): count += Ad[i][1] ...
p03495
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in ra...
def resolve(): # 整数 1 つ # n = int(input()) # 整数複数個 n, k = list(map(int, input().split())) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) # A = [list(map(int, input().split())) for i in ra...
p03495
N,K = list(map(int,input().split())) A =list(map(int,input().split())) num = [0]*2000001 for i in range(N): num[A[i]] +=1 V = 2000001 - num.count(0) if V <=K: print((0)) else: num.sort() num.reverse() print((sum(num[K:])))
N,K = list(map(int,input().split())) A =list(map(int,input().split())) num = [0]*(N+1) for i in range(N): num[A[i]] +=1 V = N+1 - num.count(0) if V <=K: print((0)) else: num.sort() num.reverse() print((sum(num[K:])))
p03495
import collections n,k = (int(i) for i in input().split()) a = list(int(i) for i in input().split()) c = collections.Counter(a) ct = 0 for i in range(k): try: ct += c.most_common()[i][1] except: break ans = n-ct if ans <0: ans = 0 print(ans)
import collections n,k = (int(i) for i in input().split()) a = list(int(i) for i in input().split()) c = collections.Counter(a) values,counts = list(zip(*c.most_common())) if len(counts) >= k: ans = sum(counts[k:]) else: ans = 0 print(ans)
p03495
from collections import Counter, deque, defaultdict n, k = list(map(int, input().split())) A = list(map(int, input().split())) t = defaultdict(int) for x in A: t[x]+=1 B = [] for x in list(t.values()): B.append(x) B.sort() if(len(B)<=k): print((0)) exit() ans = 0 for i in range(0, le...
from collections import Counter, deque, defaultdict n, k = list(map(int, input().split())) A = list(map(int, input().split())) t = defaultdict(int) for x in A: t[x]+=1 B = list(t.values()) B.sort() if(len(B)<=k): print((0)) exit() ans = sum(B[:len(B)-k]) print(ans)
p03495
from collections import Counter as C _, k = list(map(int, input().split())) a = [int(i) for i in input().split()] ans = 0 c = sorted(C(a).values()) while k < len(c): ans += c.pop(0) else: print(ans)
from collections import Counter, deque _, k = list(map(int, input().split())) a = [int(i) for i in input().split()] ans = 0 d = deque(sorted(Counter(a).values())) while k < len(d): ans += d.popleft() else: print(ans)
p03495
from collections import Counter, deque _, k = list(map(int, input().split())) a = [int(i) for i in input().split()] ans = 0 d = deque(sorted(Counter(a).values())) while k < len(d): ans += d.popleft() else: print(ans)
from collections import Counter as C _, k = list(map(int, input().split())) a = [int(i) for i in input().split()] c = list(C(a).values()) d = len(c) - k if 0 < d: print((sum(sorted(c)[:d]))) else: print((0))
p03495
from collections import Counter n, k = list(map(int, input().split())) A = Counter([int(i) for i in input().split()]).most_common() count = 0 if len(A) > k: for i in range(len(A) - k): count += A[k + i][1] print(count)
from collections import Counter N, K = list(map(int, input().split())) A = Counter([int(i) for i in input().split()]).most_common() cnt = 0 for a in A[K:]: cnt += a[1] print(cnt)
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) set_A = set(A) len_types = len(set_A) memo = [0] * N ans = 0 for num in set_A: count_num = A.count(num) memo[num-1] = count_num memo.sort() for i in memo[:N-K]: ans += i # while len_types > K: # ans += heapq....
N, K = list(map(int, input().split())) A = list(map(int, input().split())) memo = [0] * N ans = 0 for a in A: memo[a-1] += 1 memo.sort() for i in memo[:N-K]: ans += i print(ans)
p03495
from collections import Counter N, K = list(map(int, input().split())) cnt = Counter(list(map(int, input().split()))) res = 0 l = len(cnt) for i in range(l, K, -1): res += cnt.most_common(i)[-1][1] print(res)
from collections import Counter N, K = list(map(int, input().split())) cnt = Counter(list(map(int, input().split()))) res = 0 l = len(cnt) mc = cnt.most_common() for i in range(l - 1, K - 1, -1): res += mc[i][1] print(res)
p03495
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) d = Counter(a) d = d.most_common() ans = 0 for i in range(len(d) - k): ans += d[-i - 1][1] print(ans)
from collections import Counter n, k = list(map(int, input().split())) a = input().split() d = sorted(Counter(a).values()) ans = 0 for i in range(len(d) - k): ans += d[i] print(ans)
p03495
def main(): n, k = list(map(int, input().split())) A = list(map(int, input().split())) res = 0 balls = {} for ball in A: if ball in balls: balls[ball] += 1 else: balls[ball] = 1 delList = [] bucket = [0 for _ in range(n+1)] ...
def main(): n, k = list(map(int, input().split())) A = list(map(int, input().split())) res = 0 balls = {} bucket = [[] for _ in range(n+1)] for ball in A: if ball in balls: balls[ball] += 1 else: balls[ball] = 1 for key, value in l...
p03495
import queue que = queue.PriorityQueue() dic = { ord('r')+ord('g'): 'b', ord('g')+ord('b'): 'r', ord('b')+ord('r'): 'g', } while True: s = input() if s=='0': break while not que.empty(): que.get() cost = {} cost[s] = 0 que.put((0, s)...
import queue dic = { 'rg':'b', 'gr':'b', 'gb':'r', 'bg':'r', 'br':'g', 'rb':'g', } while True: s = input() if s=='0': break que = queue.PriorityQueue() l = len(s) cost = {} cost[s] = 0 que.put((0, s)) ans = -1 while not que.empt...
p00179
import queue dic = { 'rg':'b', 'gr':'b', 'gb':'r', 'bg':'r', 'br':'g', 'rb':'g', } while True: s = input() if s=='0': break que = queue.PriorityQueue() l = len(s) cost = {} cost[s] = 0 que.put((0, s)) ans = -1 while not que.empt...
import queue dic = { 'rg':'bb', 'gr':'bb', 'gb':'rr', 'bg':'rr', 'br':'gg', 'rb':'gg', } while True: s = input() if s=='0': break que = queue.PriorityQueue() l = len(s) cost = {s: 0} que.put((0, s)) aa = ['r'*l, 'g'*l, 'b'*l] ans = -...
p00179
rgb = set(["r","g","b"]) while 1: worm = input() if worm == "0": break n = len(worm) que = [worm] ref = set(worm) L = 1 cnt = flag = 0 while 1: for r in range(L): Worm = que.pop(0) if Worm in ref: continue else: ref.add(Worm) if len(set(Worm)) == 1: flag = 1 break for i...
rgb = set(["r","g","b"]) while 1: worm = input() if worm == "0": break n = len(worm) L = 1 cnt = flag = 0 queset = set([worm]) while 1: que = list(queset) queset = set() for r in range(L): Worm = que.pop(0) if len(set(Worm)) == 1: flag = 1 break for i in range(n-1): if...
p00179
rgb = set(["r","g","b"]) while 1: worm = input() if worm == "0": break n = len(worm) L = 1 cnt = flag = 0 queset = set([worm]) while 1: que = list(queset) queset = set() for r in range(L): Worm = que.pop(0) if len(set(Worm)) == 1: flag = 1 break for i in range(n-1): if...
rgb = set(["r","g","b"]) while 1: worm = input() if worm == "0": break n = len(worm) L = 1 cnt = flag = 0 queset = set([worm]) ref = set() while 1: que = list(queset) queset = set() for Worm in que: if len(set(Worm)) == 1: flag = 1 break for i in range(n-1): if Worm[i] !...
p00179
rgb = set(["r","g","b"]) while 1: worm = input() if worm == "0": break n = len(worm) L = 1 cnt = flag = 0 queset = set([worm]) ref = set() while 1: que = list(queset) queset = set() for Worm in que: if len(set(Worm)) == 1: flag = 1 break for i in range(n-1): if Worm[i] !...
dic = {"r":1,"g":2,"b":3} rgb = ["r","g","b"] while 1: worm = input() if worm == "0": break n = len(worm) ref = ["r"*n,"g"*n,"b"*n] cnt = flag = 0 queset = set([worm]) done = set() while 1: que = list(queset) queset = set() for Worm in que: if Worm in ref: flag = 1 break for...
p00179
from statistics import mean inputCount = int(eval(input())) prices = [int(eval(input())) for lp in range(inputCount)] average = mean(prices) print((int(average)))
inputCount = int(eval(input())) prices = [int(eval(input())) for lp in range(inputCount)] average = sum(prices) // inputCount print(average)
p00134
N,X=list(map(int,input().split())) L=sorted(map(int,input().split()),reverse=True) mod=10**9+7 from collections import defaultdict D=defaultdict(int) D[1,L[0]]=1 for l in L[1:]: ND=defaultdict(int) for c,s in D: k=D[c,s] if s+l+c-1<=X: ND[c+1,s+l]=(ND[c+1,s+l]+k*(c...
N,X=list(map(int,input().split())) L=sorted(map(int,input().split()),reverse=True) mod=10**9+7 D=[[0]*(X+1) for i in range(N//2+2)] D[1][L[0]]=1 for l in L[1:]: ND=[[0]*(X+1) for i in range(N//2+1)] for c in range(1,N//2+1): for s in range(X+1): if D[c][s]==0: ...
p02810
#!/usr/bin/env python3 # DSL_2_H: RMQ and RAQ # Range Minimum Query and Range Add Query # Lazy propagate segment tree from array import array import sys class SegmentTree: MAXV = 1000 * 10**5 + 1 def __init__(self, n): size = 1 while size < n: size *= 2 se...
#!/usr/bin/env python3 # DSL_2_H: RMQ and RAQ # Range Minimum Query and Range Add Query # Lazy propagate segment tree from array import array import sys class SegmentTree: MAXV = 1000 * 10**5 + 1 def __init__(self, n): size = 1 while size < n: size *= 2 se...
p02352
while 1: a=[i+1 for i in range(10)] try:b=list(map(int,input().split())) except:break for i in b:a.remove(i) print((['NO','YES'][sum([1 for i in a if sum(b[:2],i)<=20])/7>=0.5]))
while 1: a=[i+1 for i in range(10)] try:b=list(map(int,input().split())) except:break for i in b:a.remove(i) c=sum(b[:2]) print((['NO','YES'][sum([1 for i in a if c+i<=20])/7>=0.5]))
p00060
import sys for s in sys.stdin: C=[0]+[1]*10 a,b,c=list(map(int,s.split())) C[a]=0 C[b]=0 C[c]=0 if sum(C[:21-a-b])>=4:print("YES") else: print("NO")
import sys for s in sys.stdin: a,b,c=list(map(int,s.split())) x=20-a-b f=3 if x<a: f-=1 if x<b: f-=1 if x<c: f-=1 if x-f>=4:print("YES") else: print("NO")
p00060
N,K=list(map(int,input().split())) td=sorted([tuple(map(int,input().split())) for _ in range(N)],key=lambda x:-x[1]) answer=0 number=[] afterpop=[] for i in range(K): answer+=td[i][1] if td[i][0] not in number: number.append(td[i][0]) else: afterpop.append(td[i][1]) answer+=len(number)**2...
N,K=list(map(int,input().split())) td=sorted([tuple(map(int,input().split())) for _ in range(N)],key=lambda x:-x[1]) answer=0 number=set() afterpop=[] for i in range(K): answer+=td[i][1] if td[i][0] not in number: number.add(td[i][0]) else: afterpop.append(td[i][1]) answer+=(len(number))*...
p03148
N,K=list(map(int,input().split())) l=[] # 寿司リスト。ただし,「おいしさ」を第1要素にする dj=[] # 寿司タプルをそのまま入れる s=set() for i in range(N): t,d=list(map(int,input().split())) l.append((d,t)) l.sort(reverse=True) ans=K**2 j=0 # 既に食べたことのある種類の寿司を更に食べた回数 for i in range(K): # i番目に食べる寿司について while l and l[0][1] in s: ...
N,K=list(map(int,input().split())) l=[] # 寿司リスト。ただし,「おいしさ」を第1要素にする m=[] # 寿司タプルをそのまま入れる s=set() for i in range(N): t,d=list(map(int,input().split())) l.append((d,t)) l.sort(reverse=True) ans=K**2 t=0 # 既に食べたことのある種類の寿司を更に食べた回数 i=0 # l内を走査する際の添字 j=0 # m内を操作する際の添え字 for _ in range(K): # _番目に食...
p03148
from heapq import heappop, heappush from collections import defaultdict N, K = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] # Step 1: Choose greedy X.sort(key=lambda x: -x[1]) pq = [] chosen = defaultdict(int) cnt = 0 score = 0 for t, d in X[:K]: heappush(pq...
from collections import defaultdict from heapq import heappop, heappush N, K = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] X.sort(key=lambda x: x[1]) pq = [] f_x = 0 ctr = defaultdict(int) appeared = 0 for _ in range(K): t, d = X.pop() heappush(pq, (d...
p03148
import itertools n,k = list(map(int,input().split())) td = [] for i in range(n): td_tmp = list(map(int,input().split())) td.append(td_tmp) # 貪欲で td_comb = list(itertools.combinations(td, k)) ans = 0 for i in td_comb: tmp_ans = 0 cnt = 0 t_lst = [] for j in i: tm...
N, K = list(map( int, input().split())) T = [(0,0)]*N for i in range(N): t, d = list(map( int, input().split())) T[i] = (d,t) T.sort( key= None, reverse = True) C = T[:K] AC = T[K:] kiso = 0 s = 0 S = [0]*(N+1) for i in range(K): d, t = T[i] kiso += d if S[t] == 0: S[t] = 1 ...
p03148
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 def ddprint(x): if DBG: ...
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 def ddprint(x): if DBG: ...
p03148
N, K = list(map(int, input().split())) sushi = [] for i in range(N): s = list(map(int, input().split())) sushi.append(s) sushi.sort(key=lambda x: x[1], reverse=True) def find_next(start, curr, point, tlist, tcount): if start == N: return [point, curr] max_c = curr max_p = poi...
N, K = list(map(int, input().split())) sushi = [] for i in range(N): s = list(map(int, input().split())) sushi.append(s) sushi.sort(key=lambda x: x[1], reverse=True) # pick from first point = 0 neta_set = set() removable_idx = list() for i in range(K): s = sushi[i] point += s[1] i...
p03148
# D - Various Sushi import sys from collections import defaultdict import heapq readline = sys.stdin.readline dd = defaultdict(list) N, K = list(map(int, readline().split())) for i in range(N): t, d = list(map(int, readline().split())) heapq.heappush(dd[t], d*-1) dd = list(dd.values()) dd.sort(...
# D - Various Sushi import sys from collections import defaultdict import heapq readline = sys.stdin.readline dd = defaultdict(list) N, K = list(map(int, readline().split())) for i in range(N): t, d = list(map(int, readline().split())) heapq.heappush(dd[t], d*-1) dd = list(dd.values()) dd.sort(...
p03148
from heapq import heappush, heappop import sys input = sys.stdin.readline N, K = list(map(int, input().split())) sushi = [None] * N for i in range(N): t, d = list(map(int, input().split())) sushi[i] = (d, t-1) sushi.sort(reverse=True) types = set() cand = [] s = x = 0 for d, t in sushi[:K]: ...
import sys input = sys.stdin.readline N, K = list(map(int, input().split())) sushi = [None] * N for i in range(N): t, d = list(map(int, input().split())) sushi[i] = (d, t) sushi.sort(reverse=True) types = set() cand = [] s = x = 0 for d, t in sushi[:K]: if t in types: cand.append(...
p03148
nk = input().split() n = int(nk[0]) k = int(nk[1]) dtlist = [] for i in range(n): td = input().split() t = int(td[0]) d = int(td[1]) dtlist.append((d, t)) dtlist.sort(reverse=True) t_to_maxidx = {} for idx, dt in enumerate(dtlist): d, t = dt if t not in t_to_maxidx: t...
nk = input().split() n = int(nk[0]) k = int(nk[1]) dtlist = [] for i in range(n): td = input().split() t = int(td[0]) d = int(td[1]) dtlist.append((d, t)) dtlist.sort(reverse=True) t_to_maxidx = {} for idx, dt in enumerate(dtlist): d, t = dt if t not in t_to_maxidx: t...
p03148
import sys input = sys.stdin.readline N, K = list(map(int,input().split())) td = [list(map(int, input().split())) for _ in range(N)] td.sort(key=lambda x: (x[0],x[1]),reverse=True) x= [] y= [] y.append(td[0][1]) for i in range(1,N): if td[i][0] != td[i-1][0]: y.append(td[i][1]) else: ...
import sys input = sys.stdin.readline N, K = list(map(int,input().split())) td = [list(map(int, input().split())) for _ in range(N)] td.sort(key=lambda x: (x[0],x[1]),reverse=True) x= [] y= [] y.append(td[0][1]) for i in range(1,N): if td[i][0] != td[i-1][0]: y.append(td[i][1]) else: ...
p03148
from itertools import accumulate N,K = list(map(int,input().split())) td = [tuple(map(int,input().split())) for i in range(N)] td = [(x[0]-1,x[1]) for x in td] td.sort(key=lambda x:-x[1]) t = [-1]*N for i in range(N): t[td[i][0]] = 0 tdK = td[:K] for i in range(K): t[tdK[i][0]] = 1 t_used = [i ...
N,K = list(map(int,input().split())) td = [list(map(int,input().split())) for _ in range(N)] td.sort(key=lambda x:-x[1]) l,r = td[:K],td[K:] used_l = [0]*N for i in range(K): used_l[l[i][0]-1] += 1 remove = [] for i in range(K-1,-1,-1): if used_l[l[i][0]-1] >= 2: remove.append(l[i][1]) ...
p03148
from heapq import heappop, heappush, heapify N, K = list(map(int, input().split())) sushi = [] for _ in range(N): t, d = list(map(int, input().split())) sushi.append((-d, t)) heapify(sushi) maxs = [] rems = [] kinds = set() for _ in range(K): d, t = heappop(sushi) if t in kinds: ...
N, K = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(N)] sushi.sort(key=lambda x: x[1], reverse=True) score = 0 remains = [] kinds = set() for t, d in sushi[:K]: if t in kinds: remains.append(d) kinds.add(t) score += d score += len(kinds)**2 ...
p03148
n, k = list(map(int, input().split())) nai = [list(map(int, input().split())) for _ in range(n)] nai = sorted(nai, key=lambda x: -x[1]) ans = 0 aru = [] spe = set() m = 0 for i in range(k): anstmp = nai.pop(0) if(anstmp[0] not in spe): ans+=anstmp[1] spe.add(anstmp[0]) else...
n, k = list(map(int, input().split())) nai = [list(map(int, input().split())) for _ in range(n)] nai = sorted(nai, key=lambda x: -x[1]) ans = 0 aru = [] spe = set() m = 0 for i in range(k): anstmp = nai.pop(0) if(anstmp[0] not in spe): ans+=anstmp[1] spe.add(anstmp[0]) else: ...
p03148
from collections import * n, k = list(map(int, input().split())) d, t = list(zip(*sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1])) c = Counter(t[:k]) x = len(c) a = [sum(d[:k])] for i in range(k)[::-1]: if c[t[i]] > 1: c[t[i]] -= 1 a.append(a[-1] - d[i]) b = [0] fo...
n, k =list(map(int, input().split())) dt = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1] r = v = 0 a = [] s = set() for i, (d,t) in enumerate(dt, 1): if t in s: if i <= k: a.append(d) v += d else: if i > k: if not a: ...
p03148
N,K = list(map(int,input().split())) X = [] for i in range(N): t,d = list(map(int,input().split())) X.append((d,t)) X.sort(reverse=True) p,v = 0,set([]) pp = [] for i in range(K): p += X[i][0] if X[i][1] not in v: v.add(X[i][1]) else: pp.append((X[i][0],X[i][1])) ...
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # --------------------------------------...
p03148
N,K = (int(x) for x in input().split()) t_arr = [0]*(N+1) d_arr = [0]*(N+1) for i in range(N): t,d = tuple(int(x) for x in input().split()) t_arr[i+1] = t d_arr[i+1] = d td_index = list(range(1,N+1)) td_index.sort(key=lambda x:d_arr[x], reverse=True) n_dm_set = set() small_arr = [] d_dm = 0 ...
N,K = (int(x) for x in input().split()) t_arr = [0]*(N+1) d_arr = [0]*(N+1) for i in range(N): t,d = tuple(int(x) for x in input().split()) t_arr[i+1] = t d_arr[i+1] = d td_index = list(range(1,N+1)) td_index.sort(key=lambda x:d_arr[x], reverse=True) n_dm_set = set() small_arr = [] d_dm = 0 ...
p03148
import sys def r(n, k, sl): sl.sort(key=lambda x: -x[1]) tl, dl = list(zip(*sl)) gmk = set() ce = [] for s in sl[:k]: if s[0] in gmk: ce.append(s) gmk.add(s[0]) gop = sum(dl[:k]) bmk = max(len(set(tl)), k) gscr = len(gmk)**2 + gop ...
import sys def r(n, k, sl): sl.sort(key=lambda x: -x[1]) gmk = set() gop = 0 ce = [] for ti, di in sl[:k]: if ti in gmk: ce.append(di) gmk.add(ti) gop += di gscr = len(gmk)**2 + gop for ti, di in sl[k:]: if 0 >= len(ce): ...
p03148
ri = lambda: int(eval(input())) rl = lambda: list(map(int,input().split())) N,K=rl() td = [rl() for _ in range(N)] from operator import itemgetter key0 = itemgetter(0) key1 = itemgetter(1) td.sort(key=key1,reverse=True) netas = set() dup = [] for t,d in td[:K]: if t in netas: dup.append(...
n,k = list(map(int,input().split())) top = [0]*n sub = [] for i in range(n): t,d = list(map(int,input().split())) t -=1 if top[t]==0: top[t]=d else: if top[t]>=d: sub.append(d) else: sub.append(top[t]) top[t]=d top.sort() top ...
p03148
# -*- coding: utf-8 -*- def popMaxOishisa(sushis): t, d = sushis.pop() return t, d def popMinOishisa_nonUniqueNeta(sel_sushis): if len(sel_sushis["min"]) == 0: return -1, -1 t, d = min(list(sel_sushis["min"].items()), key=lambda i:i[1]) sel_sushis[t].pop() if len(sel_sushi...
# -*- coding: utf-8 -*- n, k = list(map(int, input().split())) # Store data sushis = [] neta_set = set() for i in range(n): t, d = list(map(int, input().split())) sushis.append((t,d)) neta_set.add(t) # Formatting sushis.sort(key=lambda i:i[1]) tMax = len(neta_set) # Select sushi se...
p03148
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
p03148
from heapq import heappop, heappush N, K = list(map(int, input().split())) td = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1], reverse=True) q = [] v = [] cnt = 0 for t, d in td[:K]: cnt += d if t in v: heappush(q, d) else: v.append...
from heapq import heappop, heappush N, K = list(map(int, input().split())) td = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1], reverse=True) q = [] v = set() cnt = 0 for t, d in td[:K]: cnt += d if t in v: heappush(q, d) else: v.add...
p03148
N, K = list(map(int, input().split())) td = [list(map(int, input().split())) for _ in range(N)] td.sort(key=lambda x: -x[1]) q = [] v = set() cnt = 0 for t, d in td[:K]: cnt += d if t in v: q.append(d) else: v.add(t) cnt += len(v) ** 2 ans = cnt for t, d in td[K:]: ...
N, K = list(map(int, input().split())) td = [list(map(int, input().split())) for _ in range(N)] td.sort(key=lambda x: -x[1]) q = [] v = set() sd = 0 for t, d in td[:K]: sd += d if t in v: q.append(d) v.add(t) ans = len(v) ** 2 + sd for t, d in td[K:]: if 0 >= len(q): ...
p03148
from collections import defaultdict n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) t = defaultdict(int) x = list(range(n - 1, n - k - 1, -1)) z = [0] for i in range(n - k, n): t[sushi[i][0]] += 1 z[0] += sushi[i][1] ...
import heapq n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) t = {} x = [] z = 0 for i in range(n - 1, n - k - 1, -1): ti, di = sushi[i] if ti in list(t.keys()): heapq.heappush(x, di) t[ti] += 1 e...
p03148
import sys, itertools #def input(): return sys.stdin.readline() def inpl(): return [int(i) for i in input().split()] N, K = inpl() Sushi = [] Neta = set() ans = 0 for _ in range(N): t, d = inpl() Sushi.append((d, t)) Sushi.sort(reverse = True) Db = [] Nd = [] for i in range(K): d, t = Sushi[i]...
import sys, itertools def input(): return sys.stdin.readline() def inpl(): return [int(i) for i in input().split()] N, K = inpl() Sushi = [] Neta = set() ans = 0 for _ in range(N): t, d = inpl() Sushi.append((d, t)) Sushi.sort(reverse = True) Db = [] Nd = [] for i in range(K): d, t = Sushi[i] ...
p03148
from collections import defaultdict import heapq n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) kinds = defaultdict(int) eaten = [] ans = 0 for i in range(k): neta, point = sushi.pop() kinds[neta] += 1 ans +=...
from collections import defaultdict import heapq import sys input = sys.stdin.readline n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) for _ in range(n)] sushi.sort(key=lambda x: x[1]) kinds = defaultdict(int) eaten = [] ans = 0 for i in range(k): neta, point = sushi...
p03148
N,K = list(map(int,input().split())) td = sorted([list(map(int,input().split())) for _ in range(N)],key = lambda x: (-x[1],x[0])) head = [] no_head = [] is_used = [False]*(N+1) for t,d in td[:K]: if is_used[t]: no_head.append(d) else: head.append(d) is_used[t] = True unuse...
N,K = list(map(int,input().split())) td = sorted([list(map(int,input().split())) for _ in range(N)],key = lambda x: (-x[1],x[0])) head = [] no_head = [] is_used = [False]*(N+1) for t,d in td[:K]: if is_used[t]: no_head.append(d) else: head.append(d) is_used[t] = True unuse...
p03148
N,K = list(map(int,input().split())) td = sorted([list(map(int,input().split())) for _ in range(N)],key = lambda x: (-x[1],x[0])) head = [] no_head = [] is_used = [False]*(N+1) for t,d in td[:K]: if is_used[t]: no_head.append(d) else: head.append(d) is_used[t] = True unuse...
N,K = list(map(int,input().split())) TD = [list(map(int,input().split())) for _ in [0]*N] TD.sort(key=lambda x:(-x[1],x[0])) use = TD[:K] var = set() lock = [] unlock = [] for t,d in use: if t in var: unlock.append(d) else: var.add(t) lock.append(d) unlock.sort(reverse=True)...
p03148
import itertools import operator N, K = list(map(int, input().split())) sushi = [tuple([i] + [int(x) for x in input().split()]) for i in range(N)] sushi.sort(key=operator.itemgetter(2), reverse=True) from collections import OrderedDict, deque, Counter left = OrderedDict((x[0], x) for x in sushi) base = 0 ...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from itertools import islice import operator N, K = list(map(int, input().split())) sushi = [tuple([i] + [int(x) for x in input().split()]) for i in range(N)] sushi.sort(key=operator.itemgetter(2), reverse=True) from collections import OrderedDict, deque, Coun...
p03148
def takeSecond(elem): return elem[1] n,k = list(map(int,input().split())) sushi = [list(map(int,input().split())) for i in range(n)] sushi.sort(key=takeSecond,reverse=True) selected = sushi[:k] kindset = set([item[0] for item in selected]) startKindNum = len(kindset) score = startKindNum*startKi...
def takeSecond(elem): return elem[1] n,k = list(map(int,input().split())) sushi = [list(map(int,input().split())) for i in range(n)] sushi.sort(key=takeSecond,reverse=True) ''' selected = sushi[:k] kindset = set([item[0] for item in selected]) startKindNum = len(kindset) score = startKindNum*star...
p03148
from heapq import heappush, heappop N, K = list(map(int, input().split())) log = [0]*N pre = [] ls = [] for i in range(N): t, d = list(map(int, input().split())) t = t-1 heappush(ls,(-d,t)) v = 0 n = 0 for i in range(K): d, t = heappop(ls) d = -d log[t] += 1 v += d if log[t]>1: heap...
from heapq import heappush, heappop N, K, *L = list(map(int, open(0).read().split())) ls = [] for t,d in zip(*[iter(L)]*2): ls += [(d,t)] used = [] cnt = {} hq = [] S = set() ls.sort(reverse=True) m = 0 for i in range(K): d,t = ls[i] cnt[t] = cnt.get(t,0)+1 m += d if cnt[t]>1: heappush(use...
p03148
from heapq import heappush, heappop N, K, *L = list(map(int, open(0).read().split())) ls = [] for t,d in zip(*[iter(L)]*2): ls += [(d,t)] used = [] cnt = {} hq = [] S = set() ls.sort(reverse=True) m = 0 for i in range(K): d,t = ls[i] cnt[t] = cnt.get(t,0)+1 m += d if cnt[t]>1: heappush(use...
from heapq import heappush, heappop N, K, *L = list(map(int, open(0).read().split())) ls = [] for t,d in zip(*[iter(L)]*2): ls += [(d,t)] used = [] cnt = [0]*(N+1) hq = [] S = set() ls.sort(reverse=True) m = 0 for i in range(K): d,t = ls[i] cnt[t] += 1 m += d if cnt[t]>1: used.append(d) ...
p03148
from collections import defaultdict from heapq import heappush, heappop N,K,*L = list(map(int, open(0).read().split())) dic = defaultdict(list) ls = [] for i,(t,d) in enumerate(zip(*[iter(L)]*2)): dic[t].append(d) heappush(ls,(-d,t)) S = set() pre = [] ans = 0 num = 0 for i in range(K): d,t = heappop...
N,K,*L = list(map(int, open(0).read().split())) ls = [] for i,(t,d) in enumerate(zip(*[iter(L)]*2)): ls.append((d,t)) ls.sort() S = set() pre = [] ans = 0 num = 0 for i in range(K): d,t = ls.pop() ans += d if t not in S: num += 1 S.add(t) else: pre.append(d) pre.sort(reverse=True)...
p03148
#!/usr/bin/env python3 import sys # import math # from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from operator import ite...
import sys from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). ...
p03148
from operator import itemgetter from collections import Counter import heapq N, K = [int(v) for v in input().split()] sushi = [tuple(int(v) for v in input().split()) for i in range(N)] sushi = sorted(sushi, key=itemgetter(1), reverse=True) ate_list = sushi[:K] kind_counter = Counter([s[0] for s in ate_li...
from operator import itemgetter from collections import Counter N, K = [int(v) for v in input().split()] sushi = [tuple(int(v) for v in input().split()) for i in range(N)] sushi = sorted(sushi, key=itemgetter(1), reverse=True) # # kind_counter = Counter([s[0] for s in ate_list]) # kind_cnt = len(list(kind_...
p03148
import sys import heapq as h input=sys.stdin.readline N,K=list(map(int,input().split())) sushi=[[0,0] for i in range(0,N)] for i in range(0,N): t,k=list(map(int,input().split())) sushi[i][1]=t sushi[i][0]=k sushikind=[[] for i in range(0,N+1)] for i in range(0,N): sushikind[sushi[i][1]]...
import sys import heapq as h input=sys.stdin.readline N,K=list(map(int,input().split())) sushi=[[0,0] for i in range(0,N)] for i in range(0,N): t,k=list(map(int,input().split())) sushi[i][1]=t sushi[i][0]=k sushikind=[[] for i in range(0,N+1)] for i in range(0,N): sushikind[sushi[i][1]]...
p03148
n, k = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] ab_s = sorted(ab, key=lambda x: x[1]) ab_r = list(reversed(ab_s)) t = [x[0] for x in ab_r] d = [x[1] for x in ab_r] t_set = len(set(t[:k])) d_sum = sum(d[:k]) res = [t_set**2 + d_sum] from collecti...
n, k = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] ab_s = sorted(ab, key=lambda x: x[1]) ab_r = list(reversed(ab_s)) t = [x[0] for x in ab_r] d = [x[1] for x in ab_r] t_set = len(set(t[:k])) d_sum = sum(d[:k]) res = [t_set**2 + d_sum] from collecti...
p03148
N,K = list(map(int,input().split())) TDlist = [list(map(int,input().split())) for x in range(N)] TDlist.sort(key = lambda x: x[1],reverse=True) kinds = [] seconds = [] answer = 0 for x in TDlist[:K]: if not x[0] in kinds: kinds.append(x[0]) else: seconds.append(x[1]) answer ...
N,K = list(map(int,input().split())) TDlist = [] for x in range(0,N): TDlist.append(list(map(int,input().split()))) TDlist= sorted(TDlist, key = lambda x: x[1],reverse=True) kinds = set() seconds = [] answer = 0 for x in TDlist[:K]: if not x[0] in kinds: kinds.add(x[0]) else: ...
p03148
n,k=list(map(int,input().split())) inf=10**18 sushi=[[-inf] for _ in range(n)] for i in range(n): t,d=list(map(int,input().split())) sushi[t-1].append(d) for i in range(n): sushi[i].sort(reverse=True) sushi.sort(key=lambda x:x[0],reverse=True) q=[] res=0 for i in range(k): res+=sushi[i][0] for j ...
n,k=list(map(int,input().split())) INF=10**18 sushi=[[-INF] for _ in range(n)] for _ in range(n): t,d=list(map(int,input().split())) sushi[t-1].append(d) for i in range(n): sushi[i].sort(reverse=True) sushi.sort(key=lambda x:x[0],reverse=True) q=[] res=0 for i in range(k): res+=sushi[i][0] for j ...
p03148
N,K=list(map(int,input().split())) t=[0 for i in range(N)] d=[0 for i in range(N)] for i in range(N): t[i],d[i]=list(map(int,input().split())) D=dict() for i in range(N): if not(t[i] in D): D[t[i]]=[] D[t[i]].append((d[i],i)) E=[0 for i in range(N)] for key in D: D[key].sort(reverse=...
N,K=list(map(int,input().split())) sushi=[] for i in range(N): t,d=list(map(int,input().split())) sushi.append((t,d)) sushi.sort(key=lambda x:(x[0],-x[1])) #print(sushi) X=[sushi[0][1]] Y=[] for i in range(1,N): if sushi[i-1][0]==sushi[i][0]: Y.append(sushi[i][1]) else: X.ap...
p03148
def solve(): from collections import namedtuple from heapq import heappush, heappop from operator import attrgetter import sys input = sys.stdin.readline Sushi = namedtuple('Sushi', 'taste kind') n, k = list(map(int, input().split())) e = [] for _ in range(n): ...
def solve(): from collections import deque, namedtuple from operator import attrgetter import sys input = sys.stdin.readline Sushi = namedtuple('Sushi', 'taste kind') n, k = list(map(int, input().split())) e = [] for _ in range(n): t, d = list(map(int, input().spli...
p03148
def solve(): from collections import deque, namedtuple from operator import attrgetter import sys input = sys.stdin.readline Sushi = namedtuple('Sushi', 'taste kind') n, k = list(map(int, input().split())) e = [] for _ in range(n): t, d = list(map(int, input().spli...
def main(): from heapq import heappush, heappop from operator import itemgetter import sys input = sys.stdin.readline N, K = list(map(int, input().split())) dd = [] for _ in range(N): t, d = list(map(int, input().split())) t -= 1 dd.append((d, t)) d...
p03148
from operator import itemgetter from functools import reduce N, K = list(map(int, input().split())) t, d = list(zip(*(list(map(int, input().split())) for _ in range(N)))) fn = itemgetter(0) fd = itemgetter(1) ss = sorted(zip(t, d), key=fd, reverse=True) netas = set() duplicates = [] for s in ss[:K]: if s[0]...
from heapq import heappush, heappop N, K = list(map(int, input().split())) t, d = ( list(zip(*(list(map(int, input().split())) for _ in range(N)))) if N else ((), ()) ) # おいしさについて貪欲に寿司を食べたときの満足ポイントを求める # その後、種類ボーナスを1個ずつ増やしたときの満足ポイントをそれぞれ求め、 # それらの最大値を求める S = sorted(zip(d, t), reverse=True) q = [] ...
p03148
import heapq def main(): num_sushi, chose_num = list(map(int, input().split())) data = [list(map(int, input().split())) for i in range(num_sushi)] data.sort(key=lambda x: -x[1]) delicious_heap = [] count_d, count_n = 0, 0 neta_data = [0 for i in range(num_sushi + 1)] for i ...
import heapq import sys input = sys.stdin.readline def main(): num_sushi, chose_num = list(map(int, input().split())) data = [list(map(int, input().split())) for i in range(num_sushi)] data.sort(key=lambda x: -x[1]) delicious_heap = [] count_d, count_n = 0, 0 neta_data = [0 for i ...
p03148
# -*- coding: utf-8 -*- import sys from heapq import heapify, heappush, heappop from collections import Counter 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,...
# -*- coding: utf-8 -*- import sys from heapq import heapify, heappop 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 ra...
p03148