Last time ABC today
#48 Problem
** Thoughts ** I feel like I've seen it before. TLE when counting for each element. So sort and do something pseudo-count. All you have to do now is rewrite in ascending order of the number of elements.
n, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
num = [0] * n
c = 0
t = 0
for i in range(n-1):
if a[i] != a[i+1]:
c += 1
num[a[i]-1] += c
t += 1
c = 0
else:
c += 1
s = sum(num)
t += 1
num[a[i+1]-1] = n - s
num.sort()
ans = 0
for i in range(n):
if num[i] == 0:
continue
if t <= k:
print(ans)
break
ans += num[i]
t -= 1
It's so bad that I'll be able to recover by ABC. I want to turn brown soon. see you.
Recommended Posts