逻辑题

发布时间 2023-09-07 10:48:35作者: 爱新觉罗LQ

逻辑题

OD253. 流水线

import java.util.Scanner;
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
        String[] split = in.nextLine().split(" ");
        int m = Integer.parseInt(split[0]); //  流水线
        int n = Integer.parseInt(split[1]); //  作业数
        String[] temp = in.nextLine().split(" ");
        int[] arr = new int[temp.length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(temp[i]);
        }
        Arrays.sort(arr);
        int res = 0;
        int[] sum = new int[m];
        for (int i = 0; i < arr.length; i++) {
            sum[i % m] += arr[i];
        }
        for (int i : sum) {
            res = Math.max(res, i);
        }
        System.out.println(res);
    }
}