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. 理解Hbase RowKey的字典排序;HBase Rowkey的散列与预分区设计

    HBase是三维有序存储的,是指rowkey(行键),column key(column family和qualifier)和TimeStamp(时间戳)这个三个维度是依照ASCII码表排序的. HB ...

  2. 【转载】struts应用在断网情况下启动报错解决办法(java/net/AbstractPlainSocketImpl.java:178:-1)

    无意间struts应用在有网络的情况下启动正常,在断网的情况下启动报错,报错代码如下图所示: SEVERE: Exception starting filter struts2 Class: java ...

  3. vs2015安装VAssistX以后,去除中文注释会有红色下划线方法

    ---恢复内容开始--- 环境:Visual Studio 2015 问题:代码中出现中文后会带下划线,不舒服-----解决办法. 1.安装完Visual Assist X后会在VS2015的菜单栏出 ...

  4. ElasticSearch 结构化搜索

    1.介绍 结构化搜索(Structured search) 是指有关探询那些具有内在结构数据的过程.比如日期.时间和数字都是结构化的:它们有精确的格式,我们可以对这些格式进行逻辑操作. 比较常见的操作 ...

  5. ECSHOP去版权(删除ECSHOP所有标识)

    前台部分: 1:去掉头部TITLE部分的ECSHOP演示站 Powered by ecshop前者”ECSHOP演示站”在后台商店设置 – 商店标题修改后者” Powered by ecshop”打开 ...

  6. 2017.4.19 慕课网-通过自动回复机器人学习mybatis

    开发前的分析 1.技能前提 JSP JSTL EL JS/JQUERY Servlet JavaBean JDBC(后期再用mybatis,这样体会更深) MYSQL 2.需求分析和模块划分 (1)基 ...

  7. centos 7 查看系统/硬件信息及运维常用命令+联想Y430P无线网卡驱动安装

     centos 7 查看系统/硬件信息及运维常用命令 当前环境:联想Y430P  CentOS 7.3 [root@yan-001 ~] # uname -a # 查看内核/操作系统/CPU信息的Li ...

  8. Android学习(六) 文本框边框

    BorderTextViews.java package xiaosi.BorderTextView; import android.content.Context; import android.g ...

  9. react-native 详解

    1.获取主屏幕尺寸 // 导入类库 var Dimensions = require('Dimensions'); // 样式 const styles = StyleSheet.create({ c ...

  10. [Hibernate开发之路](2)Hibernate问题

    (1)数据库驱动问题 log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j: ...