65872023-12-12 17:02:34Huni136Zenehallgatáscpp17Time limit exceeded 19/50275ms5064 KiB
#include <iostream>
#include <map>
#include <vector>
using namespace std;

map<int,int> vlmi;
vector<int> a(100002,1e9);

int binkeres(int x, int kezd, int veg)
{
     int kozep;
     int *y;
    while(kezd<=veg)
    {
       kozep=(kezd+veg)/2;
        y=&a[kozep];
       if(*y>=x && *(y-1)<x)
       {
            return kozep;
       }
       else if(*y<x && *(y+1)>=x)
       {
            return kozep+1;
       }
       else if(x>*y)
       {
            //return binkeres(x,kozep+1,veg);
            kezd=kozep+1;
       }
       else
       {
            // return binkeres(x,kezd,kozep-1);
            veg=kozep-1;
       }
    }
}


int main()
{
    int n,x,kdb;
    cin>>n>>kdb;
    //vector<int> a(n+1);
    a[0]=0;
    cin>>a[1];
    for(int i=2;i<=n;i++)
    {
        cin>>x;
        a[i]=a[i-1]+x;
        //vlmi[prevveg]=i;
    }
    int k;
   // auto seg=vlmi.end();
    //prevveg++;
    int hossz=a[n];
    for(int i=1;i<=kdb;i++)
    {
        cin>>k;
        k=k%(hossz);
        if(k==0)
        {
            cout<<n<<" ";
            continue;
        }
        if(k<a[1])
        {
            cout<<1<<" ";
        }
        else if(k>a[n-1])
        {
            //cout<<11111;
            cout<<n<<" ";
        }
        else
        {

            cout<<binkeres(k,1,n)<<" ";
        }
        
        
    }
}
SubtaskSumTestVerdictTimeMemory
base19/50
1Accepted0/03ms2516 KiB
2Accepted0/0200ms2712 KiB
3Accepted2/24ms2920 KiB
4Accepted2/24ms3144 KiB
5Accepted2/24ms3220 KiB
6Accepted3/34ms3348 KiB
7Accepted3/34ms3428 KiB
8Accepted3/34ms3556 KiB
9Accepted2/2199ms3772 KiB
10Time limit exceeded0/2210ms3996 KiB
11Time limit exceeded0/2216ms4064 KiB
12Time limit exceeded0/2217ms4204 KiB
13Time limit exceeded0/2233ms4204 KiB
14Time limit exceeded0/2211ms4216 KiB
15Time limit exceeded0/2238ms4488 KiB
16Accepted2/2192ms4324 KiB
17Time limit exceeded0/2252ms3268 KiB
18Time limit exceeded0/2238ms4440 KiB
19Time limit exceeded0/2210ms4532 KiB
20Time limit exceeded0/2250ms3616 KiB
21Time limit exceeded0/2225ms4732 KiB
22Time limit exceeded0/3250ms4868 KiB
23Time limit exceeded0/3275ms3856 KiB
24Time limit exceeded0/3236ms5064 KiB