134262025-01-07 22:34:35csdavidZenehallgatáscpp17Time limit exceeded 15/50266ms2552 KiB
#include <iostream>

using namespace std;

int n, q, x;

int binarysearch(pair<long long, long long> a[]){
    int low=0, mid, high=n-1;
    while(low<=high){
        mid=low+(high-low)/2;
        if(a[mid].first<=x&&a[mid].second>=x){
            return mid;
        }
        if(a[mid].second<x){
            low=mid+1;
        }
        else{
            high=mid-1;
        }
    }
    return mid;
}

int main()
{
    long long hossz=0;
    cin >> n >> q;
    pair<long long, long long> a[n];
    cin >> a[0].second;
    a[0].first=1;
    for(int i=1; i<n; i++){
        a[i].first=a[i-1].second+1;
        cin>>x;
        a[i].second=a[i-1].second+x;
    }
    hossz=a[n-1].second;
    for(int i=0; i<q; i++){
        cin >> x;
        x=x%hossz;
        cout << binarysearch(a)+1 << ' ';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base15/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0259ms2348 KiB
3Accepted2/23ms316 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms316 KiB
6Accepted3/33ms316 KiB
7Accepted3/33ms328 KiB
8Accepted3/33ms316 KiB
9Time limit exceeded0/2263ms2476 KiB
10Time limit exceeded0/2266ms2480 KiB
11Time limit exceeded0/2266ms2476 KiB
12Time limit exceeded0/2257ms2356 KiB
13Time limit exceeded0/2257ms2476 KiB
14Time limit exceeded0/2261ms2472 KiB
15Time limit exceeded0/2261ms2488 KiB
16Time limit exceeded0/2263ms2528 KiB
17Time limit exceeded0/2257ms2472 KiB
18Time limit exceeded0/2261ms2356 KiB
19Time limit exceeded0/2254ms2552 KiB
20Time limit exceeded0/2252ms2364 KiB
21Time limit exceeded0/2259ms2356 KiB
22Time limit exceeded0/3252ms2356 KiB
23Time limit exceeded0/3259ms2532 KiB
24Time limit exceeded0/3226ms2356 KiB