hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #은행 번호표 #288

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int m = scanner.nextInt();
    int arr[] = new int[2];
    int sum = 0;
    float hold = 0;
    float x = 0;
    for (int i = 0; i < m; i++) {
        int n = scanner.nextInt();
        x = n;
        for (int j = 0; j < arr.length; j++) {

            arr[j] = scanner.nextInt();
        }

        if (n == 1) {
            sum = arr[0] + arr[1];
        } else {
            if (arr[0] < sum) {
                hold += sum - arr[0];
                sum += arr[1];
            } else {
                sum = arr[0] + arr[1];
            }
        }

    }

    float dap = hold / x;

    System.out.printf("%.1f", dap);

}

}