AtCoder Beginner Contest 153 - Fennec vs Monster

Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
 - Attack: Fennec chooses one monster. That monster's health will decrease by 1.
 - Special Move: Fennec chooses one monster. That monster's health will become 0.
There is no way other than Attack and Special Move to decrease the monsters' health.
Fennec wins when all the monsters' healths become 0 or below.
Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

-----Constraints-----
 - 1 \leq N \leq 2 \times 10^5
 - 0 \leq K \leq 2 \times 10^5
 - 1 \leq H_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K
H_1 ... H_N

-----Output-----
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.

-----Sample Input-----
3 1
4 1 5

-----Sample Output-----
5

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.

Difficulty: EASY

Starter code:

Solutions:
(n, k) = map(int, input().split())
h = list(map(int, input().split()))
s = sorted(h)
s.reverse()
print(sum(s[k:]))


(n, k) = map(int, input().split())
print(sum(sorted(list(map(int, input().split())))[:max(n - k, 0)]))


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
m.sort(reverse=True)
print(sum(m[k:]))


R = lambda : map(int, input().split())
(n, k) = R()
print(sum(sorted(R())[:n - min(k, n)]))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
if N <= K:
	print(0)
elif K == 0:
	print(sum(H))
else:
	total = 0
	for i in H:
		total += i
	max_hp = sum(sorted(H, reverse=True)[:K])
	print(total - max_hp)


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
h = h[::-1]
print(sum(h[k:]))


(n, k) = [int(i) for i in input().split()]
a = sorted([int(i) for i in input().split()])
if k <= 0:
	print(sum(a))
else:
	print(sum(a[:-k]))


(n, k) = map(int, input().split())
h = [int(s) for s in input().split()]
ans = 0
h.sort(reverse=True)
if k >= n:
	ans = 0
else:
	ans = sum(h[k:n])
print(ans)


(N, K) = list(map(int, input().split()))
H = sorted(list(map(int, input().split())), reverse=True)
if N <= K:
	print(0)
else:
	print(sum(H[K:]))


(n, k, *h) = map(int, open(0).read().split())
if k >= n:
	print(0)
	exit()
h.sort()
print(sum(h[:n - k]))


def N():
	return int(input())

def L():
	return list(map(int, input().split()))

def NL(n):
	return [list(map(int, input().split())) for i in range(n)]
mod = pow(10, 9) + 7
import sys
import math
import collections
(n, k) = L()
h = L()
h.sort()
print(sum(h[:max(n - k, 0)]))


(N, K) = map(int, input().split())
print(sum(sorted([int(a) for a in input().split()])[::-1][K:]))


(N, K) = map(int, input().split())
HL = sorted(list(map(int, input().split())), reverse=1)
print(sum(HL[K:]))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse=True)
ans = 0
for i in range(k, n):
	ans += h[i]
print(ans)


(h, k) = map(int, input().split())
h = list(map(int, input().split()))
print(sum(sorted(h, reverse=True)[k:]))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h = sorted(h)[::-1]
del h[0:k]
print(sum(h))


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
print(sum(a[k:]))


(N, K) = list(map(int, input().split()))
H = list(map(int, input().split()))
if len(H) > K:
	print(sum(sorted(H)[0:len(H) - K]))
else:
	print(0)


(n, k) = map(int, input().split())
a = sorted(list(map(int, input().split())))
if k > n:
	k = n
print(sum(a[:n - k]))


(n, k) = map(int, input().split())
h = sorted(map(int, input().split()))
print([0, sum(h[:n - k])][n > k])


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
print(sum(l[k:]))


(n, k, *h) = map(int, open(0).read().split())
h.sort()
for i in range(k):
	if len(h) != 0:
		h.pop()
print(sum(h))


(N, K) = map(int, input().split())
H = sorted(list(map(int, input().split())), reverse=True)
print(sum(H[K:]))


(n, k) = map(int, input().split())
arr = sorted([int(x) for x in input().split()], reverse=True)
print(sum(arr[k:]))


(N, K) = list(map(int, input().split()))
H = list(map(int, input().split()))
print(sum(sorted(H)[::-1][K:]))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
H.reverse()
print(sum(H) - sum(H[0:K]))


(n, k) = map(int, input().split())
H = sorted(list(map(int, input().split())))
print(sum(H[:n - k]) if k < n else 0)


(n, k) = map(int, input().split())
(*h,) = map(int, input().split())
h.sort(reverse=True)
print(sum(h[k:]))


(N, K) = map(int, input().split())
print(sum(sorted(map(int, input().split()), reverse=True)[K:]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
s = sum(l[k:])
print(s)


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
if K <= len(H):
	print(sum(H[K:len(H) + 1]))
else:
	print(0)


(A, B) = map(int, input().split())
C = list(map(int, input().split()))
C.sort(reverse=True)
print(sum(C[B:]))


(N, K) = map(int, input().split())
H = [int(x) for x in input().split()]
H.sort(reverse=True)
print(sum(H[K:]))


(h, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse=True)
del h[0:k]
print(sum(h))


(n, k, *l) = map(int, open(0).read().split())
print([0, sum(sorted(l)[:n - k])][n > k])


(N, K) = map(int, input().split())
H = sorted([int(x) for x in input().split()])[::-1]
print(sum(H[K:]))


(N, K) = map(int, input().split())
H = [int(x) for x in input().split()]
H.sort()
if N > K:
	ans = sum(H[:N - K])
else:
	ans = 0
print(ans)


(N, K) = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
H_ls.sort(reverse=True)
print(sum(H_ls[K:]))


(n, k) = map(int, input().split())
h_list = sorted(list(map(int, input().split())))[::-1]
print(sum(h_list[k:]))


(N, K) = map(int, input().split())
mons = sorted(map(int, input().split()))
print(sum(mons[:max(0, N - K)]))


(n, k) = map(int, input().split())
h = [int(i) for i in input().split()]
h.sort()
del h[-1:-k - 1:-1]
print(sum(h))


(n, k) = map(int, input().split())
l = sorted(list(map(int, input().split())))[::-1]
print(sum(l[min(k, n):]))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l.reverse()
l = l[m:]
print(sum(l))


(N, K) = map(int, input().split())
H = input()

def ans153(N: int, K: int, H: str):
	if K == 0:
		H_list = sorted(list(map(int, H.split())))
		return sum(H_list)
	elif len(list(map(int, H.split()))) > K:
		H_list = sorted(list(map(int, H.split())))
		H_list = H_list[:-K]
		return sum(H_list)
	else:
		return 0
print(ans153(N, K, H))


(N, K) = list(map(int, input().split(' ')))
H = sorted(list(map(int, input().split(' '))), reverse=True)
Z = 0
R = 0
for (n, e) in enumerate(H):
	if n == K:
		Z = n
		break
	elif K >= len(H):
		Z = len(H)
		break
for i in H[Z:]:
	R += i
print(R)


(N, K) = map(int, input().split())
lst = list(map(int, input().split()))
if N <= K:
	print(0)
else:
	lst.sort(reverse=True)
	lst = lst[K:]
	print(sum(lst))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
print(sum(h[0:max(0, n - k)]))


(N, K) = list(map(int, input().split()))
Hlist = list(map(int, input().split()))
Hlist = sorted(Hlist, reverse=True)
if len(Hlist) >= K and K != 0:
	del Hlist[0:K]
elif len(Hlist) < K:
	del Hlist[0:len(Hlist)]
if len(Hlist) > 0:
	print(sum(Hlist))
else:
	print(len(Hlist))


(n, k) = map(int, input().split())
h = map(int, input().split())
rh = sorted(h, reverse=True)
print(sum(rh[k:]))


(a, b) = map(int, input().split())
n = list(map(int, input().split()))
n.sort(reverse=True)
n[0:b] = []
print(sum(n))


(h, n) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
print(sum(a[n:]))


(a, b) = map(int, input().split())
n = list(map(int, input().split()))
m = sorted(n)[::-1]
if a <= b:
	print('0')
else:
	print(sum(m[b:]))


(H, K) = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
print(sum(sorted(H, reverse=True)[K:]))


(n, k) = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
H.reverse()
print(sum(H[k:]))


(n, k) = map(int, input().split())
print(sum(sorted(map(int, input().split()), reverse=True)[k:]))


(n, k) = map(int, input().split())
h = [int(i) for i in input().split()]
h.sort(reverse=True)
del h[:k]
print(sum(h))


a = list(map(int, input().split()))
b = list(map(int, input().split()))
if len(b) <= a[1]:
	print('0')
elif a[1] == 0:
	print(sum(b))
else:
	b.sort(reverse=True)
	print(sum(b[a[1]:]))


(n, k) = map(int, input().split())
health = list(map(int, input().split()))
s_health = sorted(health)
if n <= k:
	print(0)
	return
print(sum(s_health[:n - k]))


(n, k, *h) = map(int, open(0).read().split())
h = sorted(h)[::-1]
for i in range(min(k, n)):
	h[i] = 0
print(sum(h))


f = lambda : map(int, input().split())
(n, k) = f()
l = sorted(f())[::-1]
if n > k:
	print(sum(l[k:]))
else:
	print(0)


import sys
import heapq
(n, k) = list(map(int, input().split()))
h = []
heapq.heapify(h)
for x in map(int, input().split()):
	heapq.heappush(h, x)
if n <= k:
	print(0)
	return
ans = 0
for x in range(n - k):
	ans += heapq.heappop(h)
print(ans)


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
ans = 0
for i in range(K, N):
	ans += H[i]
print(ans)


(n, k) = map(int, input().split())
h = sorted([int(i) for i in input().split()], reverse=1)
print(sum(h[k:]))


(N, K) = list(map(int, input().split()))
hp_list = list(map(int, input().split()))
if N <= K:
	print(0)
else:
	hp_list.sort()
	del hp_list[N - K:N]
	print(sum(hp_list))


def main():
	(n, k) = map(int, input().split(' '))
	h = list(map(int, input().split(' ')))
	h.sort(reverse=True)
	print(sum(h[k:]))

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
H = sorted(map(int, input().split()))
print(sum(H[:max(0, N - K)]))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
if k >= n:
	print(0)
else:
	h = h[:n - k]
	print(sum(h))


(n, k) = list(map(int, input().split()))
enemy = list(map(int, input().split()))
enemy.sort(reverse=True)
if k >= n:
	print(0)
else:
	for x in range(k):
		enemy[x] = 0
	print(sum(enemy))


(N, K) = map(int, input().split())
H = sorted(list(map(int, input().split())))
print(sum(H[:N - min(N, K)]))


(H, K) = map(int, input().split())
hp = list(map(int, input().split()))
hp.sort(reverse=True)
print(sum(hp[K:]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=1)
print(sum(a[k:]))


(n, k) = [int(j) for j in input().split()]
h = [int(j) for j in input().split()]
h.sort()
print(sum(h[:max(0, n - k)]))


(n, k) = map(int, input().split())
a = sorted(map(int, input().split()))
print(sum(a[0:max(0, n - k)]))


(h, n) = map(int, input().split())
x = [int(i) for i in input().split()]
y = sorted(x, reverse=True)
print(sum(y[n:]))


(N, K, *H) = map(int, open(0).read().split())
print(sum(sorted(H)[:N - min(N, K)]))


(N, K, *H) = map(int, open(0).read().split())
H.sort(reverse=True)
print(sum(H[K:]))


(N, K) = map(int, input().split())
print(sum(sorted(list(map(int, input().split())))[:max(N - K, 0)]))


(n, k) = map(int, input().split())
h = list(sorted(map(int, input().split())))
x = 0
if n > k:
	for i in range(n - k):
		x += h[i]
print(x)


(n, k) = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
h.sort()
ans = 0
for i in range(n - k):
	ans += h[i]
print(ans)


(n, k) = list(map(int, input().split()))
enemy = list(map(int, input().split()))
enemy = sorted(enemy, reverse=True)
enemy = enemy[k:]
print(sum(enemy))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
m = 0
if K < N:
	for i in range(N - K):
		m += H[i]
print(m)


(N, K) = map(int, input().split())
H = sorted(map(int, input().split()))
if K == 0:
	print(sum(H))
elif N < K:
	K = N
	del H[-K:]
	print(sum(H))
else:
	del H[-K:]
	print(sum(H))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
m = min(N, K)
H = H[:N - m]
ans = 0
for i in range(len(H)):
	ans += H[i]
print(ans)


(N, K) = map(int, input().split())
(*H,) = map(int, input().split())
H.sort()
print(sum(H[:max(N - K, 0)]))


(health, attacks) = map(int, input().split())
num_list = [num for num in map(int, input().split())]
num_list.sort(reverse=True)
print(sum(num_list[attacks:]))


(n, k) = map(int, input().split())
H = [int(i) for i in input().split()]
k = min(n, k)
H.sort()
print(sum(H[:n - k]))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h = sorted(h, reverse=True)
if k >= n:
	print(0)
else:
	print(sum(h[k:]))


(N, K) = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
print(sum(A[K:]))


(N, K) = map(int, input().split())
HP = list(map(int, input().split()))
HP.sort()
if K > 0:
	HP = HP[:-K]
print(sum(HP))


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
h.reverse()
del h[:k]
print(sum(h))


(n, k, *a) = map(int, open(0).read().split())
a.sort()
a += [0]
print(sum(a[:~k]))


(n, k) = map(int, input().split())
print(sum(sorted(map(int, input().split()))[::-1][k:]))


(n, k) = map(int, input().split())
h = [int(x) for x in input().split()]
h.sort(reverse=True)
print(sum(h[k:]))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
del H[:K]
print(sum(H))


(N, K) = [int(i) for i in input().split()]
H = sorted([int(i) for i in input().split()])[::-1]
H = H[K:]
print(sum(H))


(num, deathblow) = map(int, input().split())
enemy_table = list(map(int, input().split()))
list.sort(enemy_table, reverse=True)
sum = 0
if num <= deathblow:
	print(0)
else:
	for i in range(deathblow):
		enemy_table[i] = 0
	for j in range(num):
		sum += enemy_table[j]
	print(sum)


(n, k) = map(int, input().split())
H = sorted(list(map(int, input().split())))[::-1]
print(sum(H[k:]))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H = sorted(H)
hp = 0
for i in range(N - K):
	hp += H[i]
print(hp)


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
print(0 if N < K else sum(H[:N - K]))


(a, b) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort(reverse=True)
print(sum(lis[b:]))


R = lambda : map(int, input().split())
(n, k) = R()
print(sum(sorted(R())[:n - k]) if k < n else 0)


(n, k) = map(int, input().split())
lst = [int(i) for i in input().split()]
if len(lst) <= k:
	print(0)
	return
lst = sorted(lst)
for i in range(k):
	lst.pop()
print(sum(lst))


(n, k) = map(int, input().split())
hl = sorted(list(map(int, input().split())))
c = -k if k > 0 else n
print(sum(hl[:c]))


(n, k, *hh) = map(int, open(0).read().split())
hh.sort(reverse=True)
print(sum(hh[k:]))


(n, k) = map(int, input().split())
h = sorted(map(int, input().split()))
print(sum(h[:-k]) if k != 0 else sum(h))


f = lambda : map(int, input().split())
(n, k) = f()
l = sorted(list(f()))
k = min(k, n)
print(sum(l[:n - k]))


import sys
(n, k) = list(map(int, input().split()))
h = list(map(int, input().split()))
list.sort(h, reverse=True)
if k >= n:
	print('0')
	return
c = 0
for i in range(k, n):
	c += h[i]
print(c)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort(reverse=True)
if k >= n:
	print(0)
else:
	for i in range(k):
		l[i] = 0
	print(sum(l))


(n, k) = list(map(int, input().split()))
h = list(map(int, input().split()))
if n <= k:
	print(0)
	return
num = 0
h.sort(reverse=True)
for i in h[k:]:
	num += i
print(num)


[N, K] = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
if N <= K:
	print(0)
else:
	h = list(sorted(H))
	t = sum(h[0:N - K])
	print(t)


(N, K) = list(map(int, input().split()))
H = list(map(int, input().split()))
a = 0
if K > N:
	a = K - N
for _ in range(a):
	H.append(0)
H.sort(reverse=True)
sum = 0
for i in range(K):
	H[i] = 0
for i in range(N):
	sum += H[i]
print(sum)


(n, k) = map(int, input().split())
h = sorted(list(map(int, input().split())))
if k >= len(h):
	print(0)
	return
print(sum(h[0:n - k]))


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

def I():
	return map(int, input().split())

def X():
	return list(input())

def L():
	return list(input().split())

def l():
	return list(map(int, input().split()))

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
(n, k) = I()
h = l()
h.sort(reverse=True)
print(sum(h[k:]))


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
ls.reverse()
print(sum(ls[k:]))


import sys
from itertools import chain

def solve(N: int, K: int, H: 'List[int]'):
	H = sorted(H, reverse=True)
	return sum(H[K:])

def main():
	tokens = chain(*(line.split() for line in sys.stdin))
	N = int(next(tokens))
	K = int(next(tokens))
	H = [int(next(tokens)) for _ in range(N)]
	answer = solve(N, K, H)
	print(answer)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
h.reverse()
if k > n:
	k = n
for i in range(k):
	h[i] = 0
print(sum(h))


(N, K) = map(int, input().split())
H = [int(i) for i in input().split()]
s = sorted(H)[::-1]
ans = s[K:]
print(sum(ans))


(h, k) = list(map(int, input().split()))
lst = list(map(int, input().split()))
lst.sort()
if len(lst) >= k + 1:
	print(sum(lst[:len(lst) - k]))
else:
	print(0)


(n, k) = list(map(int, input().split()))
h = list(map(int, input().split()))
h.sort(reverse=True)
if k >= n:
	k = n
h2 = h[k:]
print(sum(h2))


(_, K) = map(int, input().split())
print(sum(sorted(map(int, input().split()), reverse=True)[K:]))


(h, k) = map(int, input().split())
H = sorted(list(map(int, input().split())))[::-1]
print(sum(H[k:]))


(N, K) = map(int, input().split())
H = sorted([int(_) for _ in input().split()])
print(0 if N <= K else sum(H[:N - K]))


(N, K) = map(int, input().split())
List = list(map(int, input().split()))
S = sorted(List)[::-1]
del S[0:K]
print(sum(S))


(N, K) = map(int, input().split())
H = [int(x) for x in input().split()]
H_sort = sorted(H, reverse=True)
print(sum(H_sort[K:]))


def main():
	(N, K) = list(map(int, input().split()))
	H = sorted([int(x) for x in input().split()])
	if K == 0:
		print(sum(H))
	elif N > K:
		print(sum(H[:-K]))
	else:
		print(0)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
s = 0
for i in range(n - k):
	s += h[i]
print(s)


def main():
	(n, k) = list(map(int, input().split()))
	h = [int(v) for v in input().split()]
	if k >= len(h):
		return 0
	monsters = sorted(h)
	monsters.reverse()
	return sum(monsters[k:])

def __starting_point():
	print(main())
__starting_point()


(N, K) = map(int, input().split())
Hlist = list(map(int, input().split()))
if N - K > 0:
	print(sum(sorted(Hlist)[:N - K]))
else:
	print(0)


(N, K) = map(int, input().split())
H = sorted([int(i) for i in input().split()])
ans = 0
for i in range(N - K):
	ans += H[i]
print(ans)


(N, H) = map(int, input().split())
Mon = list(map(int, input().split()))
Mon = sorted(Mon)[::-1]
print(sum(Mon[H:]))


(n, k, *h) = map(int, open(0).read().split())
print(sum(sorted(h)[:n - min(n, k)]))


(N, K) = map(int, input().split())
H = list(map(int, input().split()))
if N <= K:
	print(0)
else:
	H.sort(reverse=True)
	for i in range(K):
		H[i] = 0
	print(sum(H))