Черви

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
611 B
15
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n + 1], p[n + 1] = {};
    
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        p[i] = p[i - 1] + a[i];
    }
    
    int m;
    cin >> m;
    while (m--) {
        int x;
        cin >> x;
        int j = (lower_bound(p + 1, p + n + 1, x) - p);
        cout << j << endl;
    }
    
    return 0;
}

// N -> N/2 -> N/4 -> N/8 ... 1 
/*
prefix 

a[1], a[2], ..., a[n]

a[1]
a[1], a[2]
a[1], a[2], a[3]

n = 5
    1   2   3   4   5
a   2   7   3   4   9
p   2   9   12  16  25


3
1 25 11

*/