結果

問題 No.3067 +10 Seconds Clock
ユーザー ks2m
提出日時 2025-03-21 21:39:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,087 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 82,692 KB
実行使用メモリ 60,324 KB
最終ジャッジ日時 2025-03-21 21:40:17
合計ジャッジ時間 17,322 ms
ジャッジサーバーID
(参考情報)
judge3 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int z = sc.nextInt();
		int n1 = n - 1;
		int[] t = new int[n1];
		for (int i = 0; i < n1; i++) {
			t[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		int[] x = new int[k];
		for (int i = 0; i < k; i++) {
			x[i] = sc.nextInt() - 1;
		}
		sc.close();

		int ng = -1;
		int ok = k + 1;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			boolean flg = true;
			int rem = z;
			int idx = 0;
			for (int i = 0; i < n1; i++) {
				if (x[idx] == i && idx < mid) {
					rem += 10;
					idx++;
				}
				rem -= t[i];
				if (rem <= 0) {
					flg = false;
					break;
				}
			}
			if (flg) {
				ok = mid;
			} else {
				ng = mid;
			}
		}

		if (ok == k + 1) {
			System.out.println(-1);
		} else {
			System.out.println(ok);
		}
	}
}
0