結果

問題 No.1890 Many Sequences Sum Queries
ユーザー trineutrontrineutron
提出日時 2022-04-04 22:35:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 772 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 200,676 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-04 07:29:06
合計ジャッジ時間 2,848 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 25 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 12 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 28 ms
6,940 KB
testcase_11 AC 19 ms
6,944 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 20 ms
6,948 KB
testcase_14 AC 12 ms
6,944 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 2 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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
	long n, q, len = 0;
	scanf("%ld%ld", &n, &q);
	long a[100];
	for (long i = 0; i < n; i++) {
		scanf("%ld", &a[i]);
		len += a[i];
	}
	long c_idx[101], c[101];
	c_idx[0] = 0;
	c[0] = 0;
	for (long i = 0; i < n; i++) {
		c_idx[i + 1] = c_idx[i] + a[i];
		c[i + 1] = std::min(1000000000L, c[i] + a[i] * (a[i] + 1) / 2);
	}
	for (long i = 0; i < q; i++) {
		long s;
		scanf("%ld", &s);
		long l_idx = std::upper_bound(c, c + n + 1, s) - c;
		long l = c_idx[l_idx - 1], r = c_idx[l_idx];
		while (r - l > 1) {
			long mid = (l + r) / 2;
			long d = mid - c_idx[l_idx - 1];
			if (c[l_idx - 1] + d * (d + 1) / 2 >= s) {
				r = mid;
			} else {
				l = mid;
			}
		}
		if (c[n] < s or r > len) {
			r = -1;
		}
		printf("%ld\n", r);
	}
}
0