結果

問題 No.904 サメトロ
ユーザー ks2mks2m
提出日時 2019-10-11 21:47:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 883 ms / 1,000 ms
コード長 981 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 73,680 KB
実行使用メモリ 52,700 KB
最終ジャッジ日時 2023-08-16 17:35:37
合計ジャッジ時間 6,333 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
51,868 KB
testcase_01 AC 38 ms
49,704 KB
testcase_02 AC 99 ms
51,524 KB
testcase_03 AC 49 ms
49,808 KB
testcase_04 AC 112 ms
52,032 KB
testcase_05 AC 39 ms
49,268 KB
testcase_06 AC 142 ms
51,468 KB
testcase_07 AC 48 ms
49,976 KB
testcase_08 AC 285 ms
51,740 KB
testcase_09 AC 40 ms
49,328 KB
testcase_10 AC 60 ms
51,368 KB
testcase_11 AC 62 ms
52,172 KB
testcase_12 AC 39 ms
49,160 KB
testcase_13 AC 42 ms
49,276 KB
testcase_14 AC 46 ms
50,056 KB
testcase_15 AC 40 ms
49,392 KB
testcase_16 AC 60 ms
51,680 KB
testcase_17 AC 39 ms
49,928 KB
testcase_18 AC 38 ms
49,600 KB
testcase_19 AC 42 ms
50,028 KB
testcase_20 AC 38 ms
49,284 KB
testcase_21 AC 53 ms
50,568 KB
testcase_22 AC 219 ms
52,700 KB
testcase_23 AC 58 ms
51,896 KB
testcase_24 AC 78 ms
51,688 KB
testcase_25 AC 40 ms
49,228 KB
testcase_26 AC 63 ms
51,416 KB
testcase_27 AC 883 ms
51,544 KB
testcase_28 AC 44 ms
49,092 KB
testcase_29 AC 40 ms
49,536 KB
testcase_30 AC 38 ms
49,416 KB
testcase_31 AC 38 ms
49,344 KB
testcase_32 AC 38 ms
49,420 KB
testcase_33 AC 39 ms
49,352 KB
testcase_34 AC 38 ms
49,304 KB
testcase_35 AC 46 ms
50,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		int[] b = new int[n];
		int xa = 0;
		int xb = 0;
		for (int i = 1; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
			xa += a[i];
			xb += b[i];
		}
		br.close();

		a[0] = xb;
		b[0] = xa;

		int ans = 0;
		while (a[0] >= 0 && b[0] >= 0) {
			boolean flg = true;
			for (int i = 0; i < n; i++) {
				xa = 0;
				xb = 0;
				for (int j = 0; j < n; j++) {
					if (i != j) {
						xa += a[j];
						xb += b[j];
					}
				}
				if (xa < b[i] || xb < a[i]) {
					flg = false;
					break;
				}
			}
			if (flg) {
				ans++;
				a[0]--;
				b[0]--;
			} else {
				break;
			}
		}
		System.out.println(ans);
	}
}
0