結果

問題 No.77 レンガのピラミッド
ユーザー Grenache
提出日時 2015-11-06 18:33:12
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 801 bytes
コンパイル時間 3,328 ms
コンパイル使用メモリ 78,796 KB
実行使用メモリ 41,712 KB
最終ジャッジ日時 2024-09-13 13:05:21
合計ジャッジ時間 7,611 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder77 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        	sum += a[i];
        }

        int nn = (int)Math.sqrt(sum);
        int p = 0;
        int m = 0;
        for (int i = 0; i < n; i++) {
        	int tmp;
        	if (i < nn) {
        		tmp = i + 1;
        	} else {
        		tmp = Math.max(0, nn - (i - nn + 1));
        	}
        	
        	if (a[i] > tmp) {
        		p += a[i] - tmp;
        	} else {
        		m += tmp - a[i];
        	}
        }

        System.out.println(m + Math.max(0, p - m));

        sc.close();
    }
}
0