192192025-11-30 13:36:41szabelrZenehallgatáscpp17Elfogadva 50/5052ms2612 KiB
// zenehalllgatas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll binkeres(ll x, vector<ll>&zenek) {
    ll l = 1, r = zenek.size()-1;
    while (l < r) {
        ll mid = l + (r - l) / 2;
        if (x<=zenek[mid] and x>zenek[mid - 1])
            return mid;
        else if ( x <= zenek[mid - 1])
            r = mid - 1;
        else 
            l = mid + 1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k,x;
    cin >> n >> k;
    vector<ll>zenek(n+2);
    zenek[0] = 0;
    for (ll i = 1; i <= n; i++)
    {
        cin >> x;
        zenek[i] = zenek[i - 1] + x;
    }
    for (ll i = 1; i <= k; i++) {
        cin >> x;
        if (x > zenek[n] ) {
            x = x % zenek[n];
        }
        if (x == 0) {
            cout << 1;
        }
        else
            cout<<binkeres(x, zenek)<<" ";
    }

}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms500 KiB
2Elfogadva0/050ms2356 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva3/31ms316 KiB
7Elfogadva3/31ms316 KiB
8Elfogadva3/32ms316 KiB
9Elfogadva2/252ms2364 KiB
10Elfogadva2/252ms2504 KiB
11Elfogadva2/250ms2360 KiB
12Elfogadva2/252ms2256 KiB
13Elfogadva2/252ms2356 KiB
14Elfogadva2/250ms2500 KiB
15Elfogadva2/250ms2504 KiB
16Elfogadva2/250ms2316 KiB
17Elfogadva2/250ms2500 KiB
18Elfogadva2/250ms2356 KiB
19Elfogadva2/250ms2356 KiB
20Elfogadva2/250ms2612 KiB
21Elfogadva2/248ms2612 KiB
22Elfogadva3/348ms2524 KiB
23Elfogadva3/348ms2500 KiB
24Elfogadva3/350ms2356 KiB