Submission #387559

#TimeUsernameProblemLanguageResultExecution timeMemory
387559casperwangTable Tennis (info1cup20_tabletennis)C++14
35 / 100
3092 ms129996 KiB
#include <bits/stdc++.h>
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 150000;
const int MAXK = 400;
const int B = 2000;
int N, K;
int a[MAXN+MAXK+1];
bool flag[MAXN+MAXK+1];
map <int,int> arr;

bool check(int S) {
	int nowR = N+K, cnt = 0;
	for (int i = 1; i < nowR; i++) {
		while (a[i] + a[nowR] > S && nowR > i)
			nowR--;
		if (nowR > i && a[i] + a[nowR] == S) {
			flag[i] = flag[nowR] = true;
			cnt++;
			nowR--;
		}
		if (cnt == N / 2) break;
	}
	return cnt == N / 2;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N+K; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= min(N+K, B); i++) {
		for (int j = max(1, N+K-B+1); j <= N+K; j++) {
			arr[a[i] + a[j]]++;
		}
	}
	for (auto [v, c] : arr) if (c >= min(N/2, (B-K)/2) && check(v)) break;
	for (int i = 1; i <= N+K; i++) {
		if (flag[i]) cout << a[i] << ' ';
	}
	cout << '\n';
}

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:42:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |  for (auto [v, c] : arr) if (c >= min(N/2, (B-K)/2) && check(v)) break;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...