Submission #388784

# Submission time Handle Problem Language Result Execution time Memory
388784 2021-04-13T02:53:40 Z warner1129 Table Tennis (info1cup20_tabletennis) C++17
87 / 100
3000 ms 4548 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, 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 716 KB Output is correct
2 Correct 41 ms 3088 KB Output is correct
3 Correct 39 ms 3100 KB Output is correct
4 Correct 48 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 3040 KB Output is correct
2 Correct 40 ms 3132 KB Output is correct
3 Correct 42 ms 3072 KB Output is correct
4 Correct 43 ms 3068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 320 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 3 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 293 ms 4528 KB Output is correct
3 Correct 47 ms 4480 KB Output is correct
4 Correct 88 ms 4548 KB Output is correct
5 Correct 43 ms 4524 KB Output is correct
6 Correct 51 ms 4544 KB Output is correct
7 Correct 82 ms 4512 KB Output is correct
8 Correct 42 ms 4448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Execution timed out 3070 ms 2240 KB Time limit exceeded
3 Halted 0 ms 0 KB -