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


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.


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

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.