It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought MoleNOrdered piles of worms such thatI-th Pile contains ai Worms. He labeled all these worms with consecutive integers:worms in first pile is labeled with numbers1To a1 , worms in second pile is labeled with numbers a1? +?1To a1? +? a 2 And so on. See the example for a better understanding.
Mole can ' t eat all the worms (Marmot brought a lot) and, as we all know, Mole are blind, so Marmot tells him the labels of The best juicy worms. Marmot would only give Mole a worm if Mole says correctly in which pile this worm is contained.
Poor Mole asks for your help. For all juicy Worms said by Marmot, tell Mole the correct answers.
Input
The first line contains a single integer n (1?≤? N? ≤?105), the number of piles.
The second line containsNIntegers a1,? a 2,?...,? a N (1?≤? a i? ≤?103 , a1? +? a 2? +?...? +? a n? ≤?106 ), where ai is the number of worms in theI-th Pile.
The third line contains a single integer m (1?≤? M.≤?105), the number of juicy worms said by Marmot.
The fourth line containsmIntegers q1,? Q 2,?...,? Q m (1?≤? Q i? ≤? a 1? +? a 2? +?...? +? a N ), the labels of the juicy worms.
Output
Print m lines to the standard output. The i-th line should contain a integer, representing the number of the pile where the worm labeled with the numb ER qi is.
Sample Test (s) input
52 7 3 4 931 25 11
Output
153
Test instructions: give you the length of the n sequence, concatenate the n sequence sequentially, and count from the first start.
To find the first part of M that belonged to that sequence.
Idea: Record every number belongs to that little sequence.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int MAXN = 1e6;int Num[maxn];int main () {int n;scanf ("%d", &n); int cnt = 0;int m;for (int i = 1; I <= N; i++) {scanf ("%d", &m), for (int j = 0; J < m; j + +) num[++cnt] = i;} int q;scanf ("%d", &q), while (q--) {scanf ("%d", &m);p rintf ("%d\n", Num[m]);} return 0;}
Codeforces Round #271 (Div. 2)