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 containsAIWorms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1A1, worms in second pile are labeled with numbersA1? +? 1A1? +?A2 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 is blind, so marmot tells him the labels of the best juicy worms. marmot will 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 integerN(1? ≤?N? ≤? (105), the number of piles.
The second line containsNIntegersA1 ,?A2 ,?...,?AN(1? ≤?AI? ≤? 103,A1? +?A2? + ?...? +?AN? ≤? 106), whereAIIs the number of worms inI-Th pile.
The third line contains single integerM(1? ≤?M? ≤? 105), the number of juicy worms said by marmot.
The fourth line containsMIntegersQ1 ,?Q2 ,?...,?QM(1? ≤?QI? ≤?A1? +?A2? + ?...? +?AN), The labels of the juicy worms.
Output
PrintMLines to the standard output.I-Th line shoshould contain an integer, representing the number of the pile where the worm labeled with the numberQIIs.
Sample test (s) Input
52 7 3 4 931 25 11
Output
153
Question: give you the length of N sequences, connect N sequences in sequence, and count from the first one. Find the sequence where the MTH originally belongs.
Idea: record that each number belongs to that small 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);printf("%d\n", num[m]);}return 0;}
Codeforces round #271 (Div. 2)