結果

問題 No.1890 Many Sequences Sum Queries
ユーザー trineutrontrineutron
提出日時 2022-04-04 21:19:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 203,904 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-04 06:31:46
合計ジャッジ時間 4,215 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
6,816 KB
testcase_01 AC 153 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 65 ms
6,940 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 16 ms
6,940 KB
testcase_10 AC 161 ms
6,940 KB
testcase_11 AC 84 ms
6,940 KB
testcase_12 AC 115 ms
6,940 KB
testcase_13 AC 122 ms
6,940 KB
testcase_14 AC 62 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	int n, q, len = 0;
	std::cin >> n >> q;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) {
	    std::cin >> a[i];
		len += a[i];
	}
	std::vector<int64_t> c(len + 1);
	int idx = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < a[i]; j++) {
			c[idx] = j + 1;
			idx++;
		}
	}
	for (int i = 0; i < len; i++) {
		c[i + 1] += c[i];
	}
	for (int i = 0; i < q; i++) {
		int s;
		std::cin >> s;
		auto it = lower_bound(c.begin(), c.end(), s);
		if (it == c.end()) {
			std::cout << -1 << '\n';
		} else {
			std::cout << it - c.begin() << '\n';
		}
	}
}
0