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.

Sample test(s)
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 <cstdio>
#include <iostream>
int hash[1000100];
int main(){
int n;
scanf("%d",&n);
int sum=0;
int temp;
int sign=0;
for(int i=1;i<=n;++i){
scanf("%d",&temp);
sum+=temp;
for(int j=sign;j<=sum;++j){
hash[j]=i;
}
sign=sum+1;
}
scanf("%d",&n);
for(int i=0;i<n;++i){
scanf("%d",&temp);
printf("%d\n",hash[temp]);
}
return 0;
}

B. Worms Codeforces Round #271 (div2)的更多相关文章

  1. D. Flowers Codeforces Round #271(div2)

    D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...

  2. A. Keyboard Codeforces Round #271(div2)

    A. Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

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

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

  4. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  5. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  6. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  7. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  8. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  9. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

随机推荐

  1. VBA 时间相关的函数

    DateSerial DateADD Datediff http://www.yiibai.com/vba/vba_datediff_function.html https://www.techont ...

  2. python pip安装lxml失败(转)

    今天想要试试beautifulsoup4,安装的时候很顺利,然后就准备安装lxml作为解析器,没想到安装时pip直接给我报了一整页的错误. 解决过程 查看了一下错误提示,其中有如下一段: ****** ...

  3. 《JAVA核心卷I》之Java基本程序结构

    Java基本程序结构 1.类名是以大写字母开头的名词代码能够执行的类,要有main函数,且声明必须是public 2.注释:  “//”,"/**/" 行注释  "/** ...

  4. asp.net自制分页页码条控件

    用过微软的服务器控件分页的人都知道~那卡的一A啊~ 遂想自制分页页码条控件以备不时之需. 走你~ public static class PageShow { /// <summary> ...

  5. asp.net购物车,订单以及模拟支付宝支付(四)---模拟支付宝支付

    下完订单之后到支付宝付款,成功之后再返回来修改订单状态.由于只是测试,所以就没有真正的连接到支付宝,用的是一个模拟支付宝的程序 下载地址:支付宝模拟程序 这是一个vs2010的项目,本来网上找了一个模 ...

  6. mpush 服务端配置 for windows 服务自动运行

    mpush 服务端配置 以下安装部分是参照官方的步骤, 一.安装jdk1.8并配置环境变量 示例:  http://www.cnblogs.com/endv/p/6439860.html 二.Wind ...

  7. FizzBuzz and Fibonacci优化

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  8. EffectiveJava(13)使类和成员的可访问性最小化

    1.为什么要使类和成员可访问性最小化 它可以有效地解除组成系统的各模块之间的耦合关系,使得这些模块可以独立的开发 测试 优化 使用 理解和修改.提高软件的可重用性 2.成员的访问级别 私有(priva ...

  9. 网络编程readn、writen和readline函数的编写

    readn   在Linux中,read的声明为: ssize_t read(int fd, void *buf, size_t count); 它的返回值有以下情形: 1.大于0,代表成功读取的字节 ...

  10. Excel如何取消显示分页虚线

    点击普通模式,保存文件,关闭文件再打开就好了. 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing 欢迎关注,有问题一起学习欢迎留言.评论.