import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
long[] arr = new long[300001];
st = new StringTokenizer(br.readLine());
long total = 0;
for (int i=0; i<N; i++) {
int a = Integer.parseInt(st.nextToken());
arr[a] += a;
total += a;
}
PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
for (int i=1; i<300001; i++) {
pq.add(arr[i]);
}
for (int i=0; i<K; i++) {
long big_num = pq.poll();
total -= big_num;
}
System.out.println(total);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: