B. Worms
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.

Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + 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 integer n (1 ≤ n ≤ 105), the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.

The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.

The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Output

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

Examples
input
5
2 7 3 4 9
3
1 25 11
output
1
5
3
Note

For the sample input:

  • The worms with labels from [1, 2] are in the first pile.
  • The worms with labels from [3, 9] are in the second pile.
  • The worms with labels from [10, 12] are in the third pile.
  • The worms with labels from [13, 16] are in the fourth pile.
  • The worms with labels from [17, 25] are in the fifth pile.
  • 预处理解决,防止超时
  • #include<bits/stdc++.h>
    using namespace std;
    int a[1000005];
    int main()
    {
    int n,n1;
    int c,b;
    int cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>b;
    for(int j=1;j<=b;j++)
    {
    a[++cnt]=i;
    }
    }
    cin>>n1;
    for(int i=1;i<=n1;i++)
    {
    cin>>c;
    cout<<a[c]<<endl;
    }
    }

      

codeforces#271 (Div. 2)预处理的更多相关文章

  1. Codeforces 271 Div 2 C. Captain Marmot

    题目链接:http://codeforces.com/contest/474/problem/C 解题报告:给一个n,然后输入4*n个平面坐标系上的点,每四个点是一组,每个点有一个中心,这四个点可以分 ...

  2. Codeforces 271 Div 2 B. Worms

    题目链接:http://codeforces.com/contest/474/problem/B 解题报告:给你n个堆,第i个堆有ai个物品,物品的编号从1开始,第一堆的编号从1到a1,第二堆编号从a ...

  3. Codeforces 271 Div 2 A Keyboard

    题目链接:http://codeforces.com/contest/474/problem/A 解题报告:一个矩形的键盘,上面只有规定的字符,现在按的时候总是会向某个方向按偏,也就是输入一串字符后, ...

  4. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

  5. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  6. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  7. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  8. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  9. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

随机推荐

  1. jsp一句话

    <%@page import="java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*"%><%!Stri ...

  2. rsync快速删除海量文件

    rsync --delete-before -avH --progress --stats /tmp/empty/ /var/spool/postfix/maildrop/ 由于业务侧使用时,一些脚本 ...

  3. Hadoop概括——学习笔记<一>

    之前有幸在MOOC学院抽中小象学院hadoop体验课. 这是小象学院hadoop2.X概述第一章的笔记 第一章主要讲的是hadoop基础知识.老师讲的还是比较全面简单的,起码作为一个非专业码农以及数据 ...

  4. [Scala] 快学Scala A2L2

    集合 13.1 集合的三大类 所有的集合都扩展Iterable特质.集合的三大集合为Seq, Set, Map Seq是一个有先后次序的值的序列,比如数组或列表.IndexSeq允许我们通过整型下表快 ...

  5. SQL Server基础知识

    1.SQL Server表名为什么要加方括号? 这个不是必须要加,但表名或字段名如果引用了sqlserver中的关键字,数据库会不识别这到底是关键字还是表名(或字段名)时就必须要加. 比如,一个表名叫 ...

  6. PHP数组函数: array_walk()与 array_map() 的区别

    详细的介绍如下: PHP数组函数: array_walk() PHP数组函数: array_map() 实际应用中的一点区别与总结: array_walk() 主要用于对某个数组的迭代,相当于 for ...

  7. CentOS6.3 编译安装LAMP(3):编译安装 MySQL5.5.25

    所需源码包: /usr/local/src/MySQL-5.5.25/cmake-2.8.8.tar.gz /usr/local/src/MySQL-5.5.25/mysql-5.5.25.tar.g ...

  8. Linux 定时任务 Crontab命令 详解

    前言 crontab是Unix和Linux用于设置周期性被执行的指令,是互联网很常用的技术,很多任务都会设置在crontab循环执行,如果不使用crontab,那么任务就是常驻程序,这对你的程序要求比 ...

  9. 使用git status快速commit

    提交之前使用git status可以看到将要提交的文件,如果想部分提交,需要单独commit.使用下面这句可以快速commit git commit `git status | grep 'mod' ...

  10. 解决NetBeans 8.x的字体问题

    笔者喜欢用 Consolas 编码,而NetBeans的默认字体是 Monospaced 13. 尽管可以通过"选项-字体和颜色-所有语言"改变默认的字体,比如 Consolas ...