結果

問題 No.904 サメトロ
ユーザー ks2mks2m
提出日時 2019-10-11 21:47:30
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 981 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 76,516 KB
実行使用メモリ 38,200 KB
最終ジャッジ日時 2024-11-25 07:12:17
合計ジャッジ時間 6,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

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