Problem:


Score : 300 points

Problem Statement

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 1

3 1
4 1 5

Sample Output 1

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.

Sample Input 2

8 9
7 9 3 2 3 8 4 6

Sample Output 2

0

She can use Special Move on all the monsters.

Sample Input 3

3 0
1000000000 1000000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.



Sample input:
3 1
4 1 5


Sample output:
5

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, H: "List[int]"):
    H.sort()
    print(0 if N<=K else sum(H[-K:]))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
H = list(map(float, input().split()))
result = sum(reversed(sorted(H)[K:]))
print(int(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque
input = sys.stdin.readline
N, K = map(int,input().split())
H = deque(map(int,input().split()))
ans = 0
for i in range(N-K):
    ans += H[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
h = sorted(list(map(int, input().split())))

print(sum(h[:-k]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
H=list(map(int,input().split()))

H.sort()

if K>=N:
    print(0)
else:
    print(sum(H[:-K]))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc153/tasks/abc153_c
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = sorted(H)
# print('H', H)
if N <= K:
    print(0)
    exit()
if K == 0:
    print(sum(H))
    exit()
subset = H[:K + 1]
# print(subset)
print(sum(subset))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
H=list(map(int,input().split()))
sorted(H)
for i in range(N-1,-1,-1):
  if K>0:
    H[i]=0
    K-=1
  else:
    break
print(sum(H))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())
box = list(map(int, input().split()))
box.sort()
ans = sum(box[b:])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, k = LI()
H = sorted(LI())
if k >= n:
    print(0)
else:
    print(sum(H[-k:]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())

H = list(map(int, input().split()))

# 必殺技
for i in range(K):
    if len(H):
        H.pop()
    
print(sum(H))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort()
if k >= n:
    print(0)
else:
    print(sum(H[max(0, -k-1):]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n,k = map(int,input().split())
h = list(map(int,input().split()))
if n > k:
    print(sum(h[:n-k])) 
else: print(0)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
h=list(map(int,input().split()))

if n<=k:
  print(0)
  exit()

h.sort()
h=h[:-k]
print(sum(h))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N, K = InputToInt()
    H = InputToInt()
    H.sort()
    print(sum(H[:N-K]))

Submission status: Wrong Answer

Solution code:
from sys import stdin
H,K = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
sum(sorted(H)[::-1][K:])

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
arr = [int(j) for j in input().split()]
if k>= n:
	print(0)
else:
	arr.sort()
	print(sum(arr[k:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
h=list(reversed(list(map(int,input().split()))))
ans=0
for i in range(n):
    if(i>=k):
        ans+=h[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t if len(t) > 1 else t[0]
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]

N,K = I()
A = I()
if N == K:
    print(0)
else:
    print(sum(sorted(A)[:N-K]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
li = list(map(int, input().split()))

li.sort()
print(sum(li[:-k]))

Submission status: Wrong Answer

Solution code:
N, K=map(int, input().split())
H=list(map(int, input().split()))
if K>=N:
  print(0)
  exit()
if K==0:
  print(sum(H))
  exit()
  
print(sum(H[:-K]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,k = map(int, input().split())
H = sorted(map(int, input().split()))

print(sum(H[:-k]))

Submission status: Wrong Answer

Solution code:
n, k = map(int ,input().split())
h = list(map(int ,input().split()))

if n <= k:
    print(0)
elif k == 0:
    print(sum(h))
else:
    h.sort()
    t = h[n-k:]
    print(sum(t))

Submission status: Wrong Answer

Solution code:
h,n=map(int,input().split())
lists=list(map(int,input().split()))
if h>sum(lists):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K >= N:
  print(0)
else:
  A.sort()
  A = A[::-1]
  answer = K + sum(A[K:])
  print(answer)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
ls = list(map(int,input().split()))

ls = sorted(ls)

if len(ls)<3:
  print(0)
else:
  print(sum(ls[:-2]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
H = list(map(int, input().split()))

H.sort(reverse=True)
if N < K:
    K = N
for i in range(K):
    H[i] = 0
print(H)
ans = sum(H)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())

hl = list(map(int,input().split()))

hl = sorted(hl)
if n <= k:
    print(0)
elif k == 0:
    print(sum(hl))
else:
    print(sum(hl[n-k:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
if k >= n:
    print(0)
else:
    h.sort()
    ans = 0
    for i in h[: - k]:
        ans += i
    print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    h = LI()
    if n <= k:
        print(0)
        return
    h.sort()
    ans = sum(h[:-k])
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
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)

for i in range(k):
  if h:
    del h[0]
  else:
    break

print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
h = list(map(int,input().split()))
ans = 0

if(n <= k):
  print(0)
else:
  if(k == 0):
    print(sum(h))
  elif(int(n/2) <= k):
    for i in range(n-k):
      min_h = min(h)
      h[h.index(min_h)] = 10**18
      ans = ans + min_h
    print(ans)
  else:
    for i in range(k):
      max_h = max(h)
      h[h.index(max_h)] = 0
      print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
h = list(map(int,input().split()))

for i in range(k):
  max_h = max(h)
  h[h.index(max_h)] = 0
  
sum_h = sum(h)
if(sum_h == 0):
  print(0)
else:
  print(sum_h)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
health = list(map(int,input().split()))
s_health = sorted(health,reverse=True)
if n <= k:
    print(0)
    exit()
    
for i in range(k):
    del s_health[0]

print(sum(s_health))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
h = list(map(int, input().split()))
for i in range(k):
	h.remove(max(h))
	if len(h) == 0:
		break
print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
if b >= a:
    print(0)
else:
    for i in range(b):
        del lis[0]
    s = sum(lis)
    print(s)

Submission status: Time Limit Exceeded

Solution code:
# C - Fennec vs Monster

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

print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))

b.sort(reverse=True)

if len(b) <= a[1]:
    print("0")
else :
    for i in  range(a[1]):
        del b[0]
    print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
H = list(map(int, input().split()))
ans = sum(H)
for n in range(1,min(N+1,K+1)):
    ans -= sorted(H)[-n]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
H = list(map(int, input().split()))

ans = sum(H)

for n in range(1,min(N+1,K+1)):
    ans -= sorted(H)[-n]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n,k=map(int,input().split())
h=list(map(int,input().split()))

h.sort(reverse=True)

if len(h)<=k:
    print('0')
    sys.exit()
else:
    for i in range(k):
        del h[0]

a=sum(h)

print(a)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
h = list(map(int,input().split()))
m = sorted(h,reverse=True)
if n <= k:
  print(0)
  exit()
for i in range(k):
  m.pop(0)
print(sum(m))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())

if N <= K:
  print(0)
  
else:
  H = list(map(int, input().split()))
  H.sort()
  H.reverse()
  for i in range(K):
    del(H[0])
 
  c = 0
  for j in range(len(H)):
    c += H[j]
  print(c)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int , input().split())
hn = [int(num) for num in input().split()]

hn.sort(reverse = True)
for i in range(k):
  if len(hn) > 0:
    hn = hn[1:]
    
print(sum(hn))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int , input().split())
hn = [int(num) for num in input().split()]

hn.sort(reverse = True)
for i in range(k):
  if len(hn) > 0:
    hn.pop(0)
    
print(sum(hn))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
P = list(map(int,input().split()))

c=0
P.sort( reverse=True )

if k>len(P):
    k=len(P)
for i in range(k):
    if P.count==0 :
        break
    P.remove(P[0])

ans = sum(P)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
H = list(map(int, input().split()))

for i in range(K):
    if len(H) == 0:
        break
    ma = max(H)
    H.remove(ma)

ans = 0
for i in range(len(H)):
    ans += H[i]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def fennec_vs_monster():
    # 入力
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    # 体力リストの大きい順からK個だけ排除
    for i in range(K):
        # 体力リストが空でないときは以下を実行
        if i < N:
            max_H = max(H)
            H.remove(max_H)
    # 残りの体力リストを合計
    sum_H = sum(H)
    # 攻撃の回数の最小値
    return sum_H

result = fennec_vs_monster()
print(result)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
H=list(map(int, input().split()))
#Nモンスターの数、K必殺回数（モンスターは体力ゼロになる）、Hモンスターの数と各々の体力
H=sorted(H,reverse=True)
if K>=len(H):
  print(0)
else:
  for i in range(0,K):
    del H[0]
  result=sum(H)
  print(result)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
H = list(map(int,input().split()))
if N <= K:
    print(0)
else:
    for i in range(K):
        H.remove(max(H))
        #print(H)
    print(sum(H))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

n,k = map(int,input().split())
ans = 0;
h = [int(x) for x in input().split()]
for i in range(k):
    if len(h) == 0:
        break;
    m = max(h)
    h.remove(m)


if len(h) > 0:
    ans += sum(h)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
h = list(map(int,input().split()))

sumh = sum(h)

if n <= k:
    print(0)
elif k == 0:
    print(sumh)
else:
    for i in range(k):
        sumh -= max(h)
        print(sumh)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
h = list(map(int,input().split()))

h.sort(reverse = True)
t = 0

while (k > 0) and len(h)>0:
    del h[0]
    k -= 1
if len(h) == 0 :
    print(0)
else:
    t += sum(h)
    print(t)

Submission status: Time Limit Exceeded

Solution code:
from sys import exit

N, K = [int(x) for x in input().split()]
H = list([int(x) for x in input().split()])

H.sort(reverse=True)

if len(H) <= K:
    print(0)
    exit()

for _ in range(K):
    H.pop(0)

print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
import sys

N, K = (int(x) for x in input().split())
H = list(map(int, input().split()))
ans=0

if K>=N:
  print(0)
  sys.exit(0)
  
H.sort(reverse=True)
for i in range(K):
  del H[0]
for i in range(len(H)):
  ans+=H[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
H = list(map(int, input().split()))

if K >= N:
    print(0)
else:
    for i in range(K):
        del H[H.index(max(H))]
    print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
H= list(map(int,input().split()))
if(k<n):
  H.sort()
  for i in range(k):
    H.pop()
  cont=0
  for i in range(len(H)):
    while H[i]>0:
      H[i]-=1
      cont+=1
  print(cont)
else:
  print(0)

Submission status: Time Limit Exceeded

Solution code:
n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

if n<k: print(0)
else:
    for i in range(k):
        h.pop(h.index(max(h)))

    print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
H = list(map(int,input().split()))
H = sorted(H,reverse = True)
for i in range(k):
  if H == []:
    print(0)
    exit()
  else:
    H.pop(0)
print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
h = list(map(int,input().split()))

h.sort(reverse=True)

cnt = 0

for i in range(k):
  h.pop(0)
  if not h:
    break
  
for i in h:
  cnt += i

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int , input().split())
list_n = list(map(int , input().split()))
A = 0
while K > 0 and len(list_n) >= 1:
    list_n.remove(max(list_n))
    K -= 1

if K != 0 and K <= len(list_n):
    list_n.sort(reverse=True)
    del list_n[:K]

elif K != 0 and K > len(list_n):
    list_n.clear()

A += sum(list_n)

print(A)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int , input().split())
list_n = list(map(int , input().split()))
A = 0
while K > 0 and len(list_n) >= 1:
    list_n.remove(max(list_n))
    K -= 1

A += sum(list_n)

print(A)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
H = list(map(int,input().split()))
for i in range(K):
    if not H: continue
    max_val = max(H)
    H.pop(H.index(max_val))
print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse=True)
if len(h) < k:
    print(0)
else:
    [h.pop(0) for x in range(k)]
    print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    N, K = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    for i in range(K):
        if len(H) > 0:
            idx = H.index(max(H))
            H[idx] = 0
        else:
            break
    sumH = 0
    if len(H) > 0:
        sumH = sum(H)
    print(sumH)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 1
4 1 5"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8 9
7 9 3 2 3 8 4 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3 0
1000000000 1000000000 1000000000"""
        output = """3000000000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    N, K = [int(i) for i in input().split()]
    H = sorted([int(i) for i in input().split()])
    H.reverse()
    for i in range(K):
        if len(H) > 0:
            H.remove(H[0])
        else:
            break
    sumH = 0
    if len(H) > 0:
        sumH = sum(H)
    print(sumH)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 1
4 1 5"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """8 9
7 9 3 2 3 8 4 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3 0
1000000000 1000000000 1000000000"""
        output = """3000000000"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
List = list(map(int, input().split()))
List.sort()
List.reverse()
ans=0

if len(List) == K-1:
    print(0)
    quit()

def Check(List,ans):
    if sum(List) <= 0:
        print(ans)
        quit()

#print(List)

List=List[K:]

Check(List,ans)

j=0
while 1==1:
    ans+=List[j]
    List[j]=0
    Check(List,ans)
    j+=1

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())

h = list(map(int,input().split()))

turn = 0

h.sort(reverse = True)

while len(h)>0 and k>0:
    del h[0]
    k -= 1
    
turn += sum(h)

print(turn)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n, k = map(int, input().split())
H = list(map(int, input().split()))

deqh = deque(H)

for i in range(k):
    if len(deqh) == 0:
        break
    max_hp = max(deqh)
    deqh.remove(max_hp)

print(sum(deqh))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
lst=list(map(int,input().split()))
total = 0
for i in range(k):
  lst.remove(max(lst))
  if len(lst)==0:
    break;
if len(lst)==0:
  print(0)
else:
  total += sum(lst)
  print(total)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
H = [int(h) for h in input().split()]

if len(H) <= K:
  print(0)
  exit()
  
for i in range(K):
  H.remove(max(H))
print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
for i in range(k):
    if a==[]:
        break
    a.remove(a[0])
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k):
    if a==[]:
        break
    a.remove(max(a))
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = (int(x)for x in input().split())
    if n <= k:
        print(0)
        return
    hl = [int(x)for x in input().split()]
    hl = sorted(hl, reverse=1)
    for x in range(1, k+1):
        hl = hl[1:]
    print(sum(hl))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

for _ in range(K):
  H[H.index(max(H))] = 0

ans = 0
for i in H:
  ans += i
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort(reverse=True)
for i in range(k):
  try:
    h.pop(0)
  except IndexError:
    pass
print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort(reverse=True)
if n<k:
    for i in range(n):
        del h[0]
else:
    for i in range(k):
        del h[0]
print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
H = list(map(int,input().split()))

if N < K:
    K = N
for i in range(K):
    max1 = max(H)
    H.remove(max1)

sum = sum(H)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
n,k=[int(i) for i in input().split()]
l=[int(i) for i in input().split()]
for i in range(min(len(l),k)):
  l.remove(max(l))
print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc153/tasks/abc153_c

n,k=map(int,input().split())
h=list(map(int,input().split()))
for _ in range(k):
    h[h.index(max(h))]=0
sum=0
for l in h:
    sum+=l
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,K = map(int,input().split())
H = list(map(int,input().split()))
if N-K <= 0:
    print(0)
    sys.exit()
for i in range(N-(N-K)):
    H.remove(max(H))
print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
n,k = (int(x) for x in input().split())
if k>n:
    k = n
h_list = [int(i) for i in input().split()]

h_list.sort()
h_list.reverse()

for i in range(k):
    del h_list[0]

ans = sum(h_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = list(map(int, input().split()))
    monsters = list(map(int, input().split()))

    for i in range(k):
        ind = monsters.index(max(monsters))
        monsters[ind] = 0
    print(sum(monsters))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
h = list(map(int, input().split()))

for i in range(k):
    h.pop(h.index(max(h)))
    if len(h) == 0:
        break
print(sum(h))

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

if K <= len(H):
    for i in range(K):
        H.remove(max(H))
else:
    H = [0]
ans = sum(H)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
monsters, special = map(int, input().split())
HP = list(map(int, input().split()))

for i in range(special):
  HP.remove(max(HP))
  if HP == []:
    break

print(sum(HP))

Submission status: Time Limit Exceeded

Solution code:
monsters, special = map(int, input().split())
HP = list(map(int, input().split()))
HP.sort()

for i in range(special):
  HP.remove(HP[-1])
  if HP == []:
    break

print(sum(HP))

Submission status: Time Limit Exceeded

Solution code:
import sys
b = list(map(int,input().split()))

N = b[0]
K = b[1]

if N < K:
    print(0)
    sys.exit()

H = list(map(int,input().split()))

H.sort(reverse = True)

for i in range(K):
    H.pop(0)

sum_attack = sum(H)
print(sum_attack)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())

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

if K>=N:
  print(0)
else:
  for i in range(K):
    del H[0]
  print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
H = list(map(int, input().split()))

for _ in range(K):
    if len(H) == 0:
        break
    H.remove(max(H))

print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
H = list(map(int,input().split()))

count = 0
while 1:
    if K > 0:
        H[H.index(max(H))] = 0
        K -= 1
    else:
        break

count += sum(H)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
lists = list(map(int, input().split()))
if K == 0:
    print(sum(lists))
    exit()

if K <= len(lists):
    for i in range(K):
        max_lists = lists.remove(max(lists))
else:
    print(0)
    exit()

# print(lists)

print(sum(lists))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
if n <= k:
    print(0)
else:
    for i in range(k):
        l.pop(0)
    print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,M=map(int,input().split())
    monster=list(map(int,input().split()))
    monster.sort()
    cal,ct,count=0,0,0

    if M>=N:
        print(ct)
        return
    else :

        cal=N-M
        for i in range(cal):
            for j in range(monster[i]):
                ct+=1

    print(ct)
    return


main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
h = list(map(int, input().split()))

if len(h) <= k:
  ans = 0
else:
  while k > 0:
    h.remove(max(h))
    k -= 1
  ans = sum(h)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k =map(int,input().split())
l = sorted(list(map(int,input().split())))[::-1]
for i in range(min(n,k)):
  l.pop(0)
print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int,input().split())
num_list = list(map(int,input().split()))
ans = 0
num_list = np.sort(num_list)[::-1]
num_list = np.array(num_list)

if k > len(num_list):
    ans = 0
    
else:
    for i in range(k):
        num_list = np.delete(num_list,0)
    ans = sum(num_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
H=list(map(int,input().split()))
H.sort(reverse=True)
for i in range(K):
    if len(H)==0:
        break
    H.pop(0)
print(sum(H))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
s=list(map(int,input().split()))

while k>0:
  s[s.index(max(s))]=0
  k-=1
    
print(sum(s))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
s=list(map(int,input().split()))
count=0
count=0

while k>0:
  s[s.index(max(s))]=0
  k-=1
    
if len(s)!=n-1:
  for i in s:
    count+=i
      
print(count)