Codeforces Round #271 (Div. 2)

Source: Internet
Author: User

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.


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.


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
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.