79872024-01-12 09:42:29AGergoZenehallgatáscpp17Accepted 50/5052ms5128 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(0);

    int dalszam, idoszam,temp,pont,mini,maxi,ID=0;
    cin >> dalszam >> idoszam;

    vector<int> start(dalszam+1);

    start[0] = 0;

    for(int i = 1; i< dalszam+1; i++)   //start[dalszam] = length of the playlist
    {
        cin >> temp;
        start[i] = start[i-1] + temp;
        //cout << start[i]<<endl;
    }

    for(int i = 0; i < idoszam;i++)
    {
        ID = 0;
        mini = 0;
        maxi = dalszam;

        cin >> pont;
        pont = pont % start[dalszam];

        while(ID==0 && pont != 0)
        {

            if(start[mini+((maxi-mini)/2)] == pont)
            {
                ID = mini+(maxi-mini)/2;
            }
            else if(maxi-mini == 1)
            {
                ID = maxi;
            }
            else if(start[mini+((maxi-mini)/2)] > pont)
            {
                maxi = mini+((maxi-mini)/2);
            }
            else
            {
                mini = mini+((maxi-mini)/2);
            }
        }
        if(pont == 0)
        {
            ID = dalszam;
        }
        cout << ID << " ";
    }



}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/050ms2888 KiB
3Accepted2/23ms2280 KiB
4Accepted2/23ms2492 KiB
5Accepted2/23ms2672 KiB
6Accepted3/33ms2748 KiB
7Accepted3/33ms2884 KiB
8Accepted3/33ms3092 KiB
9Accepted2/252ms4144 KiB
10Accepted2/250ms4192 KiB
11Accepted2/252ms4436 KiB
12Accepted2/252ms4364 KiB
13Accepted2/250ms4376 KiB
14Accepted2/250ms4624 KiB
15Accepted2/250ms4576 KiB
16Accepted2/250ms4680 KiB
17Accepted2/250ms4552 KiB
18Accepted2/250ms4552 KiB
19Accepted2/250ms4640 KiB
20Accepted2/248ms4644 KiB
21Accepted2/248ms4640 KiB
22Accepted3/348ms4956 KiB
23Accepted3/348ms4792 KiB
24Accepted3/348ms5128 KiB