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. WCF IIS上部署服务

    一.选择应用程序池:.Net Framework 4.0集成模式 二.IIS Access is denied:程序所在文件夹给予Everyone权限 三.HTTP 错误 500.21 - Inter ...

  2. Ext JS 5 gpl版本 官方原版的下载方法

    先进入官网: 然后在导航的Products中选择Sencha Ext JS,会看到以下页面: 这时候不要单击Download按钮,而是要单击导航中的DETAILS,页面切换后,就可在底部看到GPL版本 ...

  3. git只拉取github部分代码的方法

    需求:github某个项目所有代码太大,有600+M,甚至更大:只需要拉取部分代码,一是可以降低网络消耗,二是可以降低磁盘占用 分析了下空间占用情况:发现每个项目下的.git/objects/pack ...

  4. WIN7无法卸载掉中文繁体注音输入法

    WIN7无法卸载掉中文繁体注音输入法 不知何时系统里被自动安装了个中文繁体的注音输入法,每次启动都会替换默认的简体搜狗拼音,而且最要命的是在输入法选择栏里面没有出现这个繁体的输入法,而任务栏里却总是有 ...

  5. 2017.4.10 spring-ldap官方文档学习

    官网:http://www.springframework.org/ldap 官方文档及例子(重要):http://docs.spring.io/spring-ldap/docs/2.1.0.RELE ...

  6. 2016.6.30 tomcat开启时,显示端口被占用,如何修改端口

    开启tomcat时,有时候会显示端口8080已占用,所以需要将端口改为其他值. 找到tomcat的server.xml文件,修改为8088,如图所示:

  7. C#趣味程序---水仙花数

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. Asp.Mvc将生成的视图保存为字符串

    public static class ViewExtensions { /// <summary> /// 在控制器内获取指定视图生成后的HTML /// </summary> ...

  9. sessionStorage / localStorage

    var referurl = document.referrer; //上级网址 if(referurl.indexOf('address_order')>0){ //判断是否是从上一级地址跳转 ...

  10. cmd命令速查手册

    CMD命令速查手册ASSOC显示或修改文件扩展名关联AT 计划在计算机上运行的命令和程序ATTRIB 显示或更改文件属性BREAK 设置或清除扩展式 CTRL+C检查CACLS显示或修改文件的访问控制 ...