15942022-11-28 18:46:49kicsiboglarZenehallgatáscpp11Accepted 50/5046ms6928 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
long long n,m,k,i,a,sum,j;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    vector <int> x(n+2,0);
    vector <int>::iterator it;
    x[0]=0;
    for (i=1;i<=n;++i)
    {
        cin>>a;
        x[i]=x[i-1]+a;
        sum+=a;
    }
    vector <pair<int,int> > y(m+1,{0,0});
    vector <int> megold(m+1);
    for (i=1;i<=m;++i)
    {
        cin>>k;
        k=k%sum;
       /* it=lower_bound(x.begin()+1,x.end(),k);
        cout<<it-x.begin()<<" ";*/
        y[i]={k,i};
    }
    sort(y.begin()+1,y.end());
    i=1;
    j=1;
    while (i<=n&&j<=m)
    {
        if (y[j].first<=x[i])
        {
            megold[y[j].second]=i;
            j++;
        }
        else i++;
    }
    for (i=1;i<=m;++i) cout<<megold[i]<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/046ms5112 KiB
3Accepted2/22ms2116 KiB
4Accepted2/22ms2120 KiB
5Accepted2/23ms2248 KiB
6Accepted3/33ms2604 KiB
7Accepted3/33ms2644 KiB
8Accepted3/32ms2608 KiB
9Accepted2/246ms5648 KiB
10Accepted2/246ms5888 KiB
11Accepted2/246ms5968 KiB
12Accepted2/246ms5960 KiB
13Accepted2/246ms6164 KiB
14Accepted2/246ms6372 KiB
15Accepted2/246ms6368 KiB
16Accepted2/246ms6696 KiB
17Accepted2/246ms6712 KiB
18Accepted2/246ms6916 KiB
19Accepted2/245ms6928 KiB
20Accepted2/245ms6912 KiB
21Accepted2/245ms6912 KiB
22Accepted3/346ms6908 KiB
23Accepted3/345ms6908 KiB
24Accepted3/345ms6928 KiB