Submission #388782

# Submission time Handle Problem Language Result Execution time Memory
388782 2021-04-13T02:51:22 Z warner1129 Table Tennis (info1cup20_tabletennis) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e5 + 5;

int arr[maxn];
int n, m;
vector<int> ans;

int Find(int x, bool key) {
	int ret = 0;
	for (int i = 1, j = n; i < j; i++) {
		while (i < j && arr[i] + arr[j] > x) j--;
		if (i < j && arr[i] + arr[j] == x) {
			ret += 2;
			if (key) {
				ans.emplace_back(arr[i]);
				ans.emplace_back(arr[j]);
			}
			if (ret == n - m) return ret;
		}
	}
	return ret;
}

void solve() {
	cin >> n >> m;
	n += m;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	int lim = min(n/2, m+2);
	for (int i = 1; i <= lim; i++)
		for (int j = n; j >= n - lim; j--)
			if (i < j && Find(arr[i] + arr[j], false) >= n-m) {	
				Find(arr[i] + arr[j], true);
				sort(ans.begin(), ans.end());
				for (int v : ans) cout << v << ' ';
				cout << '\n';
				return;
			}
	return;
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	solve();
	return 0;
j

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:48:1: error: 'j' was not declared in this scope
   48 | j
      | ^
tabletennis.cpp:48:1: error: expected '}' at end of input
tabletennis.cpp:44:15: note: to match this '{'
   44 | signed main() {
      |               ^