65812023-12-12 16:35:41Huni136Zenehallgatáscpp17Wrong answer 0/50300ms4456 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)
// {
//     if(kezd<=veg)
//     {
//        int 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);
//        }
//        else
//        {
//             return binkeres(x,kezd,kozep-1);
//        }
//     }
// }

void binkeres(int x, int kezd, int veg)
{
    //if(x==1)
    //{
        cout<<kezd<<" "<<veg<<endl;
    //}
    if(veg-kezd==1)
    {
        if(x>a[kezd])
        {
            cout<<veg<<" ";
            return;
        }
        else
        {
            cout<<kezd<<" ";
            return;
        }
    }
    else
    {
        int kozep=(kezd+veg)/2;
        if(x==a[kozep])
        {
            //cout<<"alma";
            cout<<kozep<<" ";
            return;
        }
        else if(x<a[kozep])
        {
            binkeres(x,kezd,kozep-1);
        }
        else
        {
            binkeres(x,kozep+1,veg);
        }
    }
}

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
        {

            binkeres(k,1,n);
        }
        // //auto it=vlmi.begin();
        // while (it!=seg && it->first<k)
        // {
        //     it++;
        // }
        // //cout<<it->second<<" ";
    }
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms2776 KiB
2Time limit exceeded0/0252ms1804 KiB
3Time limit exceeded0/2254ms2036 KiB
4Time limit exceeded0/2266ms3428 KiB
5Time limit exceeded0/2266ms2416 KiB
6Time limit exceeded0/3270ms2516 KiB
7Time limit exceeded0/3254ms2860 KiB
8Time limit exceeded0/3277ms2852 KiB
9Time limit exceeded0/2266ms2900 KiB
10Time limit exceeded0/2259ms2904 KiB
11Time limit exceeded0/2243ms3100 KiB
12Time limit exceeded0/2275ms3116 KiB
13Time limit exceeded0/2266ms3404 KiB
14Time limit exceeded0/2256ms3524 KiB
15Time limit exceeded0/2270ms3612 KiB
16Time limit exceeded0/2300ms3540 KiB
17Time limit exceeded0/2275ms3884 KiB
18Time limit exceeded0/2254ms4080 KiB
19Time limit exceeded0/2266ms4188 KiB
20Time limit exceeded0/2266ms4404 KiB
21Time limit exceeded0/2270ms4376 KiB
22Time limit exceeded0/3280ms4456 KiB
23Time limit exceeded0/3266ms4404 KiB
24Time limit exceeded0/3264ms4428 KiB