原题:
kAc有n堆糖果,每堆有A[i]个。
kAc说你只能拿m次糖果,聪明的你当然想要拿最多的糖果来吃啦啦啦~
吐槽一句(出题人好像有点大病,怪恶心的)
没什么难度,次数大于糖果数就全拿,次数少就排序
代码实现:
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
BigInteger[] arr = new BigInteger[n];
BigInteger max = new BigInteger("0");
for(int i = 0; i < arr.length; i++) {
arr[i] = sc.nextBigInteger();
}
if(m >= n) {
for(int i = 0; i < n; i++) {
max = max.add(arr[i]);
}
} else {
BigInteger temp;
for(int i = 0; i < n - 1; i++) {
for(int j = i + 1; j < n; j ++) {
if(arr[i].compareTo(arr[j]) == -1) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for(int i = 0; i < m; i++) {
max = max.add(arr[i]);
}
}
System.out.println(max);
}
}