β Optimal Goodies (Contest)
Optimal Goodies (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
int n, k, j;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
k=sc.nextInt();
j=sc.nextInt();
int arr[]=new int[n];
int t=0;
for(int i=0; i<n;i++){
if(i==j-1){
t=sc.nextInt();
arr[i]=Integer.MAX_VALUE;
continue;
}
arr[i]=sc.nextInt();
}
Arrays.sort(arr);
for(int i=0; i<k-1;i++){
t += arr[i];
}
System.out.println(t);
}
}
///method 02
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
// Your code here
Scanner reader=new Scanner(System.in);
int N=reader.nextInt();
int K=reader.nextInt();
int J=reader.nextInt();
PriorityQueue<Integer>list=new PriorityQueue<>();
int sum=0;
for(int i=1;i<=N;i++){
int Z=reader.nextInt();
if(i==J){
sum=Z;
continue;
}
list.add(Z);
}
while(K!=1){
sum+=list.remove();
K--;
}
System.out.println(sum);
}
}
Last updated