66352023-12-14 08:25:15Huni136Zenehallgatáscpp17Time limit exceeded 27/50266ms5236 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])
       {
            kezd=kozep+1;
       }
       else
       {
            veg=kozep-1;
       }
    }
}


int main()
{
    int n,x,kdb;
    cin>>n>>kdb;
    a[0]=0;
    cin>>a[1];
    for(int i=2;i<=n;i++)
    {
        cin>>x;
        a[i]=a[i-1]+x;
    }
    int k;
    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<<n<<" ";
        }
        else
        {

            cout<<binkeres(k,1,n)<<" ";
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base27/50
1Accepted0/04ms2516 KiB
2Time limit exceeded0/0203ms2856 KiB
3Accepted2/26ms2976 KiB
4Accepted2/24ms3104 KiB
5Accepted2/26ms3328 KiB
6Accepted3/34ms3504 KiB
7Accepted3/34ms3868 KiB
8Accepted3/34ms3820 KiB
9Time limit exceeded0/2202ms4040 KiB
10Accepted2/2194ms4020 KiB
11Accepted2/2196ms3912 KiB
12Accepted2/2192ms4236 KiB
13Accepted2/2192ms4432 KiB
14Time limit exceeded0/2217ms4408 KiB
15Time limit exceeded0/2248ms4404 KiB
16Accepted2/2192ms4628 KiB
17Time limit exceeded0/2232ms4632 KiB
18Time limit exceeded0/2234ms4728 KiB
19Accepted2/2192ms4852 KiB
20Time limit exceeded0/2219ms4980 KiB
21Time limit exceeded0/2266ms4020 KiB
22Time limit exceeded0/3229ms5236 KiB
23Time limit exceeded0/3206ms5084 KiB
24Time limit exceeded0/3211ms5172 KiB