1602021-02-03 20:17:58kovacs.peter.18fZenehallgatáscpp11Runtime error 0/50298ms17072 KiB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct result {
	int time;
	int song;
};

vector<result> resultS;

int find(int time, int begin, int length) {
	if (length == 1) {
		return resultS[begin].song;
	}
	if (resultS[begin + length / 2].time > time) {
		return find(time, begin, length / 2);
	}
	return find(time, begin + length / 2, length / 2 + length % 2);
}

int main() {
	cin.sync_with_stdio(false);
	cin.tie(nullptr);

	// belovassuk a két listát
	// az idõpontot lemásoljuk egy másik vektorba, amit rendezünk
	// a megoldásokat egy harmadik vektorban tároljuk, ebben keresünk
	int N, K;
	cin >> N >> K;
	vector<int> lengthS(N);
	int full_length = 0;
	for (auto& e : lengthS) {
		cin >> e;
		full_length += e;
	}
	vector<int> timeS(K);
	for (auto& e : timeS) {
		cin >> e;
	}
	vector<int> sorted_timeS = timeS;
	sort(sorted_timeS.begin(), sorted_timeS.end());
	int song = 0;
	int length = 0;
	for (auto e : sorted_timeS) {
		while (length + full_length < e) {
			length += full_length;
		}
		while (length < e) {
			song = song % N + 1;
			length += lengthS[song - 1];
		}
		result current;
		current.time = e;
		current.song = song;
	}
	for (auto e : timeS) {
		cout << find(e, 0, K) << " ";
	}
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/02ms1800 KiB
2Runtime error0/035ms5664 KiB
3Runtime error0/24ms3428 KiB
4Runtime error0/24ms3440 KiB
5Runtime error0/27ms3468 KiB
6Runtime error0/37ms3480 KiB
7Runtime error0/37ms3500 KiB
8Runtime error0/37ms3516 KiB
9Runtime error0/235ms7248 KiB
10Runtime error0/235ms8424 KiB
11Runtime error0/237ms9184 KiB
12Runtime error0/239ms9988 KiB
13Runtime error0/250ms10640 KiB
14Runtime error0/268ms11368 KiB
15Runtime error0/282ms12080 KiB
16Runtime error0/297ms12912 KiB
17Runtime error0/2130ms13728 KiB
18Time limit exceeded0/2236ms14484 KiB
19Time limit exceeded0/2228ms13280 KiB
20Time limit exceeded0/2216ms13984 KiB
21Time limit exceeded0/2239ms14788 KiB
22Time limit exceeded0/3298ms15448 KiB
23Time limit exceeded0/3259ms16468 KiB
24Time limit exceeded0/3298ms17072 KiB