235342026-01-24 12:07:59KateTaylorWalking In The Parkcpp17Wrong answer 19/100331ms21160 KiB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	vector<pair<ll, int>> v;
	map<ll, int> pos;
	cin >> a[0];
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	cin >> b[0];
	pos[b[0]] = 0;
	for (int i = 1; i < m; i++) {
		cin >> b[i];
		b[i] += b[i - 1];
		pos[b[i]] = i;
	}
	if (a.back() != b.back()) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		if (!pos.count(a[i])) continue;
		v.push_back({ pos[a[i]], i });
	}
	vector<pair<ll, int>> dp = { {(ll)1e18, 1e9} };
	vector<int> par(n, -1);
	for (auto p : v) {
		int i = p.second, x = p.first;
		int pp = lower_bound(dp.begin(), dp.end(), make_pair((ll)x, i)) - dp.begin();
		if (pp == dp.size() - 1) {
			dp[pp] = p;
			dp.push_back({ (ll)1e18, 1e9 });
		}
		else dp[pp] = p;
		if (pp) par[i] = dp[pp - 1].second;
	}
	vector<int> ans;
	int curr = n - 1;
	while (ans.size() < k && curr != -1) {
		ans.push_back(curr);
		curr = par[curr];
	}
	if (ans.size() < k) {
		cout << -1;
		return 0;
	}
	reverse(ans.begin(), ans.end());
	ans.pop_back();
	for (int x : ans) cout << ++x << " ";
	cout << "\n";
	for (int x : ans) cout << pos[a[x]] + 1 << " ";
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
subtask219/19
3Accepted170ms16892 KiB
4Accepted172ms17132 KiB
5Accepted184ms17772 KiB
6Accepted165ms17808 KiB
7Accepted174ms17980 KiB
8Accepted128ms15924 KiB
9Accepted201ms19240 KiB
subtask30/23
10Accepted2ms508 KiB
11Accepted2ms316 KiB
12Accepted2ms316 KiB
13Wrong answer2ms500 KiB
14Accepted1ms316 KiB
15Accepted1ms316 KiB
subtask40/16
16Wrong answer2ms672 KiB
17Wrong answer2ms316 KiB
18Wrong answer2ms316 KiB
19Accepted1ms316 KiB
20Wrong answer2ms316 KiB
21Accepted1ms316 KiB
22Wrong answer2ms316 KiB
subtask50/42
23Wrong answer326ms18340 KiB
24Wrong answer284ms18616 KiB
25Accepted331ms19620 KiB
26Accepted287ms19288 KiB
27Wrong answer273ms19552 KiB
28Accepted142ms15924 KiB
29Wrong answer277ms21160 KiB