結果

問題 No.1890 Many Sequences Sum Queries
ユーザー suminoeno7suminoeno7
提出日時 2023-04-01 19:27:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 72,328 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-24 18:19:04
合計ジャッジ時間 2,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
4,364 KB
testcase_01 AC 176 ms
4,368 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 67 ms
4,368 KB
testcase_08 AC 15 ms
4,368 KB
testcase_09 AC 19 ms
4,368 KB
testcase_10 AC 176 ms
4,368 KB
testcase_11 AC 86 ms
4,368 KB
testcase_12 AC 121 ms
4,368 KB
testcase_13 AC 129 ms
4,368 KB
testcase_14 AC 68 ms
4,368 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long> b;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= a[i]; j++) {
            b.push_back(j);
        }
    }
    for (int i = 1; i < (int)b.size(); i++) {
        b[i] += b[i - 1];
    }
    for (int i = 0; i < q; i++) {
        long long s;
        cin >> s;
        auto itr = lower_bound(b.begin(), b.end(), s);
        if (itr == b.end()) cout << -1 << endl;
        else {
            int idx = distance(b.begin(), itr);
            cout << idx + 1 << endl;
        }
    }
    return 0;
}
0