122842024-12-11 12:10:19szasztundeZenehallgatáscpp17Time limit exceeded 15/50257ms1352 KiB
//#include <iostream>
#include <bits/stdc++.h>
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
base15/50
1Accepted0/01ms508 KiB
2Time limit exceeded0/0247ms1332 KiB
3Accepted2/23ms320 KiB
4Accepted2/23ms320 KiB
5Accepted2/23ms320 KiB
6Accepted3/33ms320 KiB
7Accepted3/33ms320 KiB
8Accepted3/33ms320 KiB
9Time limit exceeded0/2257ms1332 KiB
10Time limit exceeded0/2256ms1352 KiB
11Time limit exceeded0/2250ms1172 KiB
12Time limit exceeded0/2246ms1336 KiB
13Time limit exceeded0/2254ms1312 KiB
14Time limit exceeded0/2254ms1340 KiB
15Time limit exceeded0/2247ms1248 KiB
16Time limit exceeded0/2243ms1332 KiB
17Time limit exceeded0/2254ms1332 KiB
18Time limit exceeded0/2245ms1336 KiB
19Time limit exceeded0/2250ms1336 KiB
20Time limit exceeded0/2238ms1336 KiB
21Time limit exceeded0/2241ms1336 KiB
22Time limit exceeded0/3248ms1336 KiB
23Time limit exceeded0/3248ms1212 KiB
24Time limit exceeded0/3221ms1336 KiB