Codeforces 474B. Worms
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.
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.
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.
5
2 7 3 4 9
3
1 25 11
1
5
3
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 <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
int main()
{
int n,m;
int ans[],i,j=,k,num;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&num);
for(k=;k<num;k++){
ans[j++]=i;
}
}
scanf("%d",&m);
for(i=;i<m;i++){
scanf("%d",&num);
printf("%d\n",ans[num]);
}
return ;
}
Codeforces 474B. Worms的更多相关文章
- Codeforces 474B Worms 二分法(水
主题链接:http://codeforces.com/contest/474/problem/B #include <iostream> #include <cmath> #i ...
- CodeForces 474B Worms (水题,二分)
题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...
- CodeForces 474B(标记用法)
CodeForces 474B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descript ...
- CodeForces 474B E(Contest #1)
题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...
- Worms
474B Worms time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #271 (Div. 2)-B. Worms
http://codeforces.com/problemset/problem/474/B B. Worms time limit per test 1 second memory limit pe ...
- Codeforces 271 Div 2 B. Worms
题目链接:http://codeforces.com/contest/474/problem/B 解题报告:给你n个堆,第i个堆有ai个物品,物品的编号从1开始,第一堆的编号从1到a1,第二堆编号从a ...
- Codeforces Round #474-B(贪心)
一.题目链接 http://codeforces.com/contest/960/problem/B 二.题意 给定三个数字$N, k1, k2$,接下来给出两组数$a[]$和$b[]$,每组数$N$ ...
- B. Worms Codeforces Round #271 (div2)
B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
随机推荐
- StackExchange.Redis 之 Set集合 类型示例
话不多说直接上代码: // set添加单个元素 stopwatch.Start(); "); stopwatch.Stop(); Console.WriteLine("set添加单 ...
- python range函数(42)
在python中使用最多的除了print函数 就是 for循环 了,那么这里就不得不介绍一下python内置函数range函数! 一.range函数简介 python range函数可创建一个整数列表 ...
- Objective-C编程 — 类和继承
讲述面向对象中的一个重要概念——继承,使用继承 可以方便地在已有类的基础上进行扩展,定义一个具有父 类全部功能的新类. 父类和子类 我们在定义一个新类的时候,经常会遇到要定义的新类是某个类的扩展或者是 ...
- jni 文件切割合并
最近学习c++,看到很多常用的例子,比如文件切割,切割后后缀可以自定义,别人就无法从表面的一个文件看出是什么,也无法查看到原文件信息,只有合并后才能识别这庐山真面目 实现也比较粗暴,首先在应用层定义好 ...
- redis 5.0.7 源码阅读——字典dict
redis中字典相关的文件为:dict.h与dict.c 与其说是一个字典,道不如说是一个哈希表. 一.数据结构 dictEntry typedef struct dictEntry { void * ...
- k8s CNI插件简单了解
Kubernetes网络模型本身对某些特定的网络功能有一定要求,但在实现方面也具有一定的灵活性.业界已经有不少不同的网络方案,来满足特定的环境和要求. CNI(container network in ...
- OBS使用教程
OBS使用教程 OBS使用教程:录屏热键的设置 视频:基础画布分辨率1920/1080 1366,768输出缩放分辨率常用FPS值 30或者60 输出:输出模式:高级录像:编码器x264码率控制 CB ...
- mysql必知必会--排序检索数据
排序数据 其实,检索出的数据并不是以纯粹的随机顺序显示的.如果不排 序,数据一般将以它在底层表中出现的顺序显示.这可以是数据最初 添加到表中的顺序.但是,如果数据后来进行过更新或删除,则此顺 序将会受 ...
- ihandy2019笔记编程真题
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- libgdiplus安装配置
1.下载安装包:wget http://download.mono-project.com/sources/libgdiplus/libgdiplus0-6.0.4.tar.gz2.解压缩.编译安装 ...