This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int N, K;
int a[MAXN+MAXK+1];
bool flag[MAXN+MAXK+1];
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 L = 1; L <= K+1; L++) {
int cnt;
for (int R = N; R <= N+K; R++) {
if (R-L+1 < N) continue;
fill(flag+1, flag+1+N+K, 0);
int S = a[L] + a[R];
cnt = 1;
flag[L] = flag[R] = true;
int nowR = R-1;
for (int i = L+1; i < nowR; i++) {
while (a[i] + a[nowR] > S && nowR > i)
nowR--;
if (a[i] + a[nowR] == S) {
flag[i] = flag[nowR] = true;
cnt++;
nowR--;
}
}
if (cnt == N / 2) break;
}
if (cnt == N / 2) 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:40:3: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
40 | if (cnt == N / 2) break;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |