# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482080 | Yazan_Alattar | Table Tennis (info1cup20_tabletennis) | C++14 | 314 ms | 33776 KiB |
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 <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 151007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
vector <int> v;
int n, k, a[M];
int solve(int sum)
{
v.clear();
int l = 1, r = n + k;
while(l < r){
if(v.size() == n) break;
if(a[l] + a[r] == sum){
v.pb(l);
v.pb(r);
++l;
--r;
}
else if(a[l] + a[r] > sum) --r;
else ++l;
}
return ((int)v.size() == n);
}
int main()
{
scanf("%d%d", &n, &k);
for(int i = 1; i <= n + k; ++i) scanf("%d", &a[i]);
sort(a + 1, a + n + k + 1);
int res = 0;
if(n <= 4 * k){
for(int i = 1; i <= n + k; ++i){
for(int j = i + 1; j <= n + k; ++j){
res = solve(a[i] + a[j]);
if(res) break;
}
if(res) break;
}
}
else{
map <int,int> cnt;
for(int i = 1; i <= 2 * k; ++i) for(int j = n - k; j <= n + k; ++j) ++cnt[a[i] + a[j]];
for(auto i : cnt){
if(i.S >= k){
res = solve(i.F);
if(res) break;
}
}
}
sort(all(v));
for(auto i : v) printf("%d ", a[i]);
printf("\n");
return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
Compilation message (stderr)
# | 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... |