結果

問題 No.3472 ジャッジキューの待ち時間クエリ
コンテスト
ユーザー ks2m
提出日時 2026-03-06 22:42:09
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 1,401 ms / 2,000 ms
コード長 844 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,632 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 67,092 KB
最終ジャッジ日時 2026-03-06 23:26:16
合計ジャッジ時間 16,321 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
サンプル 10 点 AC * 3
Small 30 点 AC * 7
Large 60 点 AC * 7
合計 100 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.PrintWriter;
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 q = sc.nextInt();
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
		}

		long[] a = new long[n + 1];
		for (int i = 0; i < n; i++) {
			a[i + 1] = a[i] + t[i];
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			long x = sc.nextLong();
			int idx = binarySearch(a, x);
			pw.println(idx);
		}
		pw.flush();
		sc.close();
	}

	static int binarySearch(long[] array, long val) {
		int ng = array.length;
		int ok = -1;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if (array[mid] <= val) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		return ok;
	}
}
0