122372024-12-10 10:54:46szasztundeZenehallgatáscpp17Accepted 50/5054ms1412 KiB
#include <iostream>

using namespace std;
int a[100001]={0};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k,x,e,u,jo,kk;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]=a[i-1]+a[i];
    }
    for(int i=1;i<=k;i++)
    {
        cin>>x;
        x=x%a[n];
        if (x<a[1]) cout<<1<<" ";
        else if(x>a[n-1]) cout<<n<<" ";
        else{
            e=1; u=n; jo=0;
            while(e<=u && !jo)
            {
                kk=(e+u)/2;
                if(a[kk]>=x && a[kk-1]<x) jo=kk;
                else if(a[kk+1]>=x && a[kk]<x) jo=kk+1;
                else if(x>a[kk]) e=kk+1;
                else u=kk-1;
            }
            cout<<jo<<" ";
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms320 KiB
2Accepted0/054ms1336 KiB
3Accepted2/21ms320 KiB
4Accepted2/21ms320 KiB
5Accepted2/21ms368 KiB
6Accepted3/31ms320 KiB
7Accepted3/31ms320 KiB
8Accepted3/31ms320 KiB
9Accepted2/254ms1192 KiB
10Accepted2/254ms1336 KiB
11Accepted2/254ms1336 KiB
12Accepted2/254ms1400 KiB
13Accepted2/252ms1344 KiB
14Accepted2/252ms1336 KiB
15Accepted2/252ms1180 KiB
16Accepted2/252ms1336 KiB
17Accepted2/252ms1336 KiB
18Accepted2/252ms1160 KiB
19Accepted2/252ms1412 KiB
20Accepted2/252ms1336 KiB
21Accepted2/250ms1344 KiB
22Accepted3/350ms1356 KiB
23Accepted3/350ms1360 KiB
24Accepted3/352ms1336 KiB