Cold you anyone help me? why do i have wrong answer??? (?o?;;)/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws IOException {
// TODO 自動生成されたメソッド・スタブ
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.valueOf(input.readLine());
String str1 = input.readLine();
String[] str2 = str1.split(" ");
ArrayList<Integer> test = new ArrayList<Integer>();
for (int i = 0 ; i < num ; i++ ){
test.add(Integer.valueOf(str2[i]));
}
int cost = Integer.valueOf(input.readLine());
Collections.sort(test);
int sum = 0 ;
int bar = 0;
if ( 0 < cost ) {
if (cost <= num){
if ( test.get( cost - 1 ) < 0){
bar = ( - test.get(cost - 1) );
sum += ( - test.get(cost - 1) ) * cost;
}
}
for (int i = 0 ; i < Math.min(cost,num) ; i++ ){
if ( test.get(i) < 0 ){
sum += ( - test.get(i) ) - bar;
}
}
}
System.out.println(sum);
}
}