核心思想
贪心,每次选最大的两个~
代码
import java.util.*;
public class Main {
public static void main(String[] args) {
final long MOD = (long) (1e9 + 7);
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
Long[] nums = new Long[n];
for(int i = 0; i < n; i++){
nums[i] = scanner.nextLong();
}
Arrays.sort(nums);
if(n > 1) {
int idx = n - 2;
for (int i = 0; i < m; i++) {
long a = nums[idx];
long b = nums[idx + 1];
a = (a * b) % MOD;
b = 1L;
nums[idx] = a;
nums[idx + 1] = b;
idx --;
}
}
long res = 0L;
for(Long num : nums){
res = (res + num) % MOD;
}
System.out.println(res);
}
}
标签:届秋招,scanner,idx,真题,int,res,nums,long,第三场
From: https://www.cnblogs.com/ganyq/p/18110078