【华为机试】2024年真题C卷汇总(java)
一、题目
二、输入输出
三、示例
四、解题思路
五、参考代码
/*
* @#coding: utf-8
* @Author: mgc
* @Date: 2024-02-02 17:47:00
* @LastEditors: Do not edit
* @LastEditTime: 2024-02-02 17:48:55
*/
// import java.util.*;
// import java.util.HashMap;
// import java.util.Scanner;
// import java.util.regex.Matcher;
// import java.util.stream.Stream;
// import java.util.regex.Pattern;
// import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int M = in.nextInt();
int[] requirements = new int[M];
for (int i = 0; i < M; i++) {
requirements[i] = in.nextInt();
}
int minManpower = Integer.MAX_VALUE;
Arrays.sort(requirements);
for (int i = 0; i <= M / 2; i++) {
int j = M - 1 - i;
minManpower = Math.min(minManpower, requirements[i] + requirements[j]);
}
System.out.println(minManpower);
}
}