본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 28417번 스케이트보드

by 현장 2023. 12. 30.

-Code

import java.util.Arrays;
import java.util.Scanner;

public class _28417 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int res = 0;

        for (int i = 0; i < n; i++) {
            int[] two_track = new int[2];
            int[] five_track = new int[5];

            for (int j = 0; j < 2; j++) {
                two_track[j] = sc.nextInt();
            }

            for (int j = 0; j < 5; j++) {
                five_track[j] = sc.nextInt();
            }

            Arrays.sort(five_track);

            int max_two_track = Arrays.stream(two_track).max().getAsInt();
            int[] temp = Arrays.copyOfRange(five_track, 3, 5);
            int max_total_five_track = Arrays.stream(temp).sum();

            res = Math.max(res, max_two_track + max_total_five_track);
        }

        System.out.println(res);
    }
}