58602023-10-04 16:26:35Tina0731Zenehallgatáscpp14Accepted 50/50103ms20984 KiB
#include <iostream>
#include <bits/stdc++.h>

using namespace std;
/*
5 3
3 2 7 8 1
10 50 20
*/

/*
8 6
10 2 7 15 20 30 2 4
100 40 200 170 80 60
*/


int main()
{
    int n, k;
    cin>>n>>k;
    int t[n+1], t2[n+1];
    t2[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>t[i];
        t2[i]=t2[i-1]+t[i];
    }
    int ker[n+1];
    for(int i=1;i<=k;i++)
        cin>>ker[i];



    vector<int> e;
    for(int i=1;i<=k;i++)
    {
        int o=ker[i]/t2[n];
        ker[i]=ker[i]-o*t2[n];
        //cout<<"xx";
        int jobb=n;
        int bal=1;
        int kozep=(jobb+bal)/2;
        while(bal+1<jobb)
        {
            //cout<<"ball: "<<bal<<endl;
            //cout<<"jobb: "<<jobb<<endl<<endl;
            if(t2[kozep]<=ker[i])
            {
                bal=kozep;
                kozep=(jobb+bal)/2;
            }
            else if(t2[kozep]>=ker[i])
            {
                jobb=kozep;
                kozep=(jobb+bal)/2;
            }
        }
        if(ker[i]>t2[bal])
            e.push_back(jobb);
        else
            e.push_back(bal);
            //cout<<"ball: "<<t2[bal]<<endl;
           //cout<<"jobb: "<<t2[jobb]<<endl;
       // cout<<endl<<endl;
    }
    for(int x:e)
        cout<<x<<" ";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/0103ms6404 KiB
3Accepted2/24ms3100 KiB
4Accepted2/23ms3144 KiB
5Accepted2/23ms3276 KiB
6Accepted3/33ms3496 KiB
7Accepted3/33ms3708 KiB
8Accepted3/33ms3912 KiB
9Accepted2/2103ms8192 KiB
10Accepted2/2103ms9144 KiB
11Accepted2/2101ms10120 KiB
12Accepted2/2101ms11140 KiB
13Accepted2/298ms11896 KiB
14Accepted2/298ms12556 KiB
15Accepted2/298ms13416 KiB
16Accepted2/298ms14628 KiB
17Accepted2/297ms15192 KiB
18Accepted2/297ms16012 KiB
19Accepted2/296ms16848 KiB
20Accepted2/293ms17604 KiB
21Accepted2/293ms18424 KiB
22Accepted3/393ms19484 KiB
23Accepted3/393ms20188 KiB
24Accepted3/393ms20984 KiB