https://vjudge.net/problem/CodeForces-474B/origin

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 ≤ 103a1 + 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.

判断该标号的物品在哪一段

OT(附未通过代码 以便补题):

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cstring> using namespace std; int a[100005] = {0};
int main()
{
int n = 0;
cin >> n;
int sum = 0 , add = 0;
for(int i = 0;i<n;i++)
{
cin >> add;
sum += add;
a[i] = sum;
}
int m = 0;
int test = 0;
cin >> m;
for(int i = 0;i<m;i++)
{
cin >> test;
int p = n/2;
if(test <= a[0])
{
cout << 1 << endl;
continue;
}
while(1)
if(test > a[p])
{
p = (n+p)/2;
if(test > a[p-1] && test <= a[p])
break;
if(test > a[p] && test <= a[p+1])
{
p+=1;
break;
}
}
else
{
p = p/2;
if(test > a[p-1] && test <= a[p])
break;
if(test > a[p] && test <= a[p+1])
{
p+=1;
break;
}
}
cout << p+1 << endl;
}
return 0;
}

  

B - Worms

B - Worms (未解决的更多相关文章

  1. C/C++编译和链接过程详解 (重定向表,导出符号表,未解决符号表)

    详解link  有 些人写C/C++(以下假定为C++)程序,对unresolved external link或者duplicated external simbol的错误信息不知所措(因为这样的错 ...

  2. 直接请求json文件爬取天眼查企业信息(未解决验证码问题)——python3实现

    几个月前...省略一堆剧情...直接请求json文件爬取企业信息未成功,在知乎提问后,得到解决,有大佬说带上全部headers和cookie是可以的,我就又去试了下,果然可以(之前自己试的时候不行,没 ...

  3. 记一次未解决的异常:java.lang.NoClassDefFoundError: net/sf/json/JSONObject

    原因:Jetty会导致这个问题,Tomcat可以正常启动   一.异常产生现象 使用json-lib转换实体类/字符串,跑单元测试没问题,但是启动jetty后调用JSONArray.fromObjec ...

  4. Ajax返回中文乱码问题(未解决)

    (未解决) 暂时使用办法:改用返回Map<String,String>形式的返回值,在ajax中获取json形式的数据.

  5. openerp学习笔记 计算字段、关联字段(7.0中非计算字段、关联字段只读时无法修改保存的问题暂未解决)

    计算字段.关联字段,对象修改时自动变更保存(当 store=True 时),当 store=False 时,默认不支持过滤和分组7.0中非计算字段.关联字段只读时无法修改保存的问题暂未解决 示例代码: ...

  6. oracle,wamp,FZ突然出现问题,求解决方案(未解决,最终系统还原)

    -----背景------- 系统:win7  64位oracle 11g(11.1)每天都用oracle.用toad for oracle .电脑固定IP.未更改任何配置信息.用了几个月,突然出现了 ...

  7. (转载) C/C++编译和链接过程详解 (重定向表,导出符号表,未解决符号表)

    转载http://blog.csdn.net/neo_ustc/article/details/9024839 有 些人写C/C++(以下假定为C++)程序,对unresolved external ...

  8. tomcat中显示本地图片①(未解决)

    <本模块文仅作为学习过程中的自我总结,有需要可参看,欢迎指导与提出建议,很多地方可能断章取义,理解不到位,虚心求学.谢谢!> 资料查阅原因:2018/7/10(做项目中显示详情页面,从数据 ...

  9. JIRA状态为任务结束,但是解决结果为未解决相关配置

    1.JIRA状态为任务结束,但是解决结果为未解决,如下图所示: 2.在工作流->界面->结果处理中进行解决结果的配置(首先确保界面配置中有“解决结果”字段). 3.点击“结果处理”,进行结 ...

  10. [未解决]Exception in thread "main" java.lang.IllegalArgumentException: offset (0) + length (8) exceed the capacity of the array: 6

    调用这个方法 是报错,未解决 binfo.setTradeAmount(Double.parseDouble(new String(result.getValue(Bytes.toBytes(fami ...

随机推荐

  1. JAVA的那些数据结构实现总结,实现,扩容说明

    能沉淀下来的东西,往往都很基础,整理了下JAVA中遇到的数据结构 目录大纲: 到目前接触到的 有几个说明: 可扩容数组 ArrayList 扩容数组的实现, 满了后扩容,扩容在1.5倍,通过copy过 ...

  2. 【拥抱鸿蒙】Flutter+Cursor轻松打造HarmonyOS应用(二)

    这是[Flutter+Cursor轻松打造HarmonyOS应用]系列的第二篇.前一篇已经介绍了如何搭建Flutter鸿蒙应用开发环境,就让我们一起来看看如何借助Cursor让鸿蒙App开发更快更简单 ...

  3. Java基于线程池和AQS模拟高并发

    概述   <手写高并发下线程安全的单例模式>主要介绍使用枚举类实现JAVA单例模式,以及在高并发环境下验证此单例模式是线程安全的.本文借助ReentrantLock.CountDownLa ...

  4. 洛谷P1333 瑞瑞的木棍 字符串 最短路

    说在前面 用M↓写的第一篇题解,欢迎提出意见. 题目描述 瑞瑞有一堆的玩具木棍,每根木棍的两端分别被染上了某种颜色,现在他突然有了一个想法,想要把这些木棍连在一起拼成一条线,并且使得木棍与木棍相接触的 ...

  5. qt激光加工软件开发——日志模块

    本篇主要介绍该加工软件的日志模块 实现的功能: 主界面日志栏显示 分级显示 本地保存 简单的调用机制 目前选择的是qInstallMessageHandler,毕竟是qt亲儿子(Qt 5.0以上版本) ...

  6. k8s service访问偶发超时问题

    问题现象 在某个集群节点上的服务访问service服务:端口,会出现偶发timeout的问题,集群有的节点不会出现访问timeout的问题 问题处理 查看bridge-nf-call-iptables ...

  7. vue3 + springboot实现微信登录

    创建VUE3项目 创建初始文件 进入项目存放位置 右键用命令行打开(终端打开) npm create vite@latest wechat-report --template vue npm:包管理需 ...

  8. 袋鼠云数栈DTinsight与10家信创厂家完成产品兼容互认证,携手共建信创生态圈

    信创产业是国家数据安全.网络安全的基础,也是"新基建"的重要内容,它将成为拉动经济发展的重要抓手之一.随着国际竞争形势发生新的变化,力争掌握核心科技的"自主可控" ...

  9. 官宣 | 袋鼠云获过亿元C+轮融资,深耕国产自研数字化技术与服务

    近日,国内领先的数字化技术与服务提供商--袋鼠云宣布完成过亿元C+轮融资,本轮融资由源星昱瀚基金.国中资本.深创投投资. 本轮融资资金将主要用于袋鼠云核心产品的研发.产品生态体系建设和市场营销推广等方 ...

  10. 3-7softmax回归的简洁实现

    3-7softmax回归的简洁实现 import torch from torch import nn from d2l import torch as d2l batch_size = 256 tr ...