7322022-01-01 10:28:26kismartongZenehallgatáscpp14Accepted 50/50115ms27500 KiB
#include <bits/stdc++.h>
using namespace std;

void ps(vector<int> arr, int psa[], int n) {
	psa[0] = arr[0];
	for (int i = 1; i < n; i++)
		psa[i] = psa[i-1] + arr[i];
}

int bs(int arr[], int l, int r, int x) {
	while (l <= r) {
		int m = l + (r-l) / 2;
		if (arr[m] == x)
			return m;
		if (arr[m] > x && arr[m-1] < x)
			return m;
		if (arr[m] < x)
			l = m + 1;
		else
			r = m - 1;
	}
	return -1;
}

int main() {
	int n, k, t;
	cin >> n >> k;
	vector<int> idok;
	vector<int> kerd;
	for (int i = 0; i < n; i++) {
		cin >> t;
		idok.push_back(t);
	}
	for (int i = 0; i < k; i++) {
		cin >> t;
		kerd.push_back(t);
	}
	int *psa = new int[n];
	ps(idok, psa, n);
	for (int i = 0; i < k; i++) {
		cout << bs(psa, 0, n-1, kerd[i] % psa[n-1])+1 << " ";
	}
	cout << '\n';
}

SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1908 KiB
2Accepted0/0101ms6664 KiB
3Accepted2/23ms3492 KiB
4Accepted2/22ms3500 KiB
5Accepted2/22ms3516 KiB
6Accepted3/32ms3532 KiB
7Accepted3/33ms3548 KiB
8Accepted3/32ms3564 KiB
9Accepted2/298ms8184 KiB
10Accepted2/2104ms9632 KiB
11Accepted2/298ms11060 KiB
12Accepted2/2101ms12492 KiB
13Accepted2/2104ms13848 KiB
14Accepted2/2115ms15120 KiB
15Accepted2/292ms16456 KiB
16Accepted2/292ms17860 KiB
17Accepted2/296ms19124 KiB
18Accepted2/292ms20432 KiB
19Accepted2/290ms21684 KiB
20Accepted2/289ms22816 KiB
21Accepted2/286ms23992 KiB
22Accepted3/389ms25168 KiB
23Accepted3/386ms26340 KiB
24Accepted3/390ms27500 KiB