Codeforces Gym 100571A A. Cursed Query offline

Source: Internet
Author: User

A. Cursed Query
Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/gym/100571/problem/A

Description

De Prezer loves movies and series. He had watched the Troy for like The Times and also he was a big fan of the Supernatural series. So, he does some researches and found a cursed object which had n lights on it and initially all of them were Turned off. Becauseof theTroy, he called that object Troy.

He looked and saw a note on the IT in khikulish (language of people of Khikuland): "Ma in Hame Rah Umadim, Hala Migi ...? ... Mage man De prezer am k mikhay mano ...? .... Man SE sale ... To Boro .... Beshur manam miram ... o mishuram ".

He doesn ' t know  khikulish , so just ignored the note and tested The  Troy .

He realized the light number  i  stays turned on for Exactly  a i  seconds, and then it turns itself off (if it is Turned on, in Time  t , in Time t + a i -1 it'll is turned on, but on Time  t + a< /em> I  it won ' t is) and the next light would be turned on (If  i < n , next light number  I + 1, otherwise it is light with Number 1).

For example if n = 2 and we turn on the first light in time 0, it'll be turned on hole interval [0, a1) and in hole interval [a1, a1 + a2] The second light wil L is turned on and so on.

In time 0 He turns on the light number 1.

De Prezer also loves query. So he gives you q queries. In each query he'll give you an integer t (the time a revengeful ghost attacked him) and you should print the Number of the light which is turned on, in time t.

Input

The first line of input contains the integers n and q.

The second line contains n space separated integers, a1, a2, ..., a n .

The next Q lines, each line contains a single integer t .

1 ≤ n, q ≤105

1 ≤ ai ≤109

1 ≤ t ≤10

Output

For each query, print the answer on one line.

Sample Input

5 7
1 2 3) 4 5
1
2
3
7
14
15
16

Sample Output

2
2
3
4
5
1
2

HINT

Test instructions

Give you some lights, the first lantern will be on [0,A1] when the second stack light is on [A1,A1+A2], and then the clatter, circulation

Q A question, ask you in t seconds, is which stack light in the light

The following:

I do it offline, but I can feel two points.

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************ll A[maxn];ll SUM[MAXN];structnode{ll x, Y, z;}; Node QUERY[MAXN];BOOLCMP (node A,node b) {returna.x<b.x;}BOOLCMP1 (node A,node b) {returna.y<b.y;}intMain () {ll n,q; N=read (), q=read ();  for(intI=1; i<=n;i++) A[i]=read ();  for(intI=1; i<=n;i++) Sum[i]+=a[i]+sum[i-1];  for(intI=1; i<=q;i++) {query[i].x=read (); query[i].x%=Sum[n]; Query[i].y=i; } sort (Query+1, query+1+q,cmp); intj=1;  for(intI=1; i<=q;i++)    {         while(sum[j]<=query[i].x&&j<N) J++; Query[i].z=J; } sort (Query+1, query+1+Q,CMP1);  for(intI=1; i<=q;i++) printf ("%d\n", query[i].z);}

Codeforces Gym 100571A A. Cursed Query offline

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.