65882023-12-12 17:03:27Huni136Zenehallgatáscpp17Time limit exceeded 39/50259ms5072 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;
    while(kezd<=veg)
    {
       kozep=(kezd+veg)/2;

       if(a[kozep]>=x && a[kozep-1]<x)
       {
            return kozep;
       }
       else if(a[kozep]<x && a[kozep+1]>=x)
       {
            return kozep+1;
       }
       else if(x>a[kozep])
       {
            //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
base39/50
1Accepted0/03ms2524 KiB
2Accepted0/0195ms2748 KiB
3Accepted2/26ms2928 KiB
4Accepted2/26ms3008 KiB
5Accepted2/26ms3136 KiB
6Accepted3/36ms3220 KiB
7Accepted3/36ms3220 KiB
8Accepted3/36ms3348 KiB
9Time limit exceeded0/2259ms3564 KiB
10Time limit exceeded0/2210ms3768 KiB
11Time limit exceeded0/2237ms4196 KiB
12Accepted2/2197ms4252 KiB
13Accepted2/2194ms4212 KiB
14Accepted2/2194ms4428 KiB
15Accepted2/2196ms4644 KiB
16Accepted2/2194ms4652 KiB
17Accepted2/2193ms4736 KiB
18Accepted2/2188ms4832 KiB
19Time limit exceeded0/2250ms4652 KiB
20Accepted2/2193ms4872 KiB
21Accepted2/2188ms4864 KiB
22Time limit exceeded0/3216ms5008 KiB
23Accepted3/3185ms5064 KiB
24Accepted3/3187ms5072 KiB