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;
typedef long long ll;
vector<ll>a;
ll n, k;
int main(){
cin >> n >> k;
a.resize(n + k);
for(int i = 0; i < n + k; i++)
cin >> a[i];
ll sum = 0;
for(auto i: a)
sum += i;
sort(a.begin(), a.end());
if(n + k <= 18){
for(int mask = 0; mask < (1 << (n + k)); mask++){
ll cnt = 0, mn = 1e9, mx = -1, sum2 = sum;
map<ll, ll>mp;
for(int j = 0; j < n + k; j++){
if((mask >> j) % 2 != 0){
//cout << a[j] << ' ';
cnt++;
sum2 -= a[j];
}
else{
mn = min(mn, a[j]);
mx = max(mx, a[j]);
mp[a[j]]++;
}
}
// cout << endl;
if(cnt != k)
continue;
if(sum2 % (n / 2) != 0)
continue;
ll bl = sum2 / (n / 2);
//cout << "Look: " << sum2 << ' ' << bl << endl;
bool ok = false;
for(int j = 0; j < n + k; j++){
if((mask >> j )% 2 != 0)
bl = bl;
else{
if(mp[bl - a[j]] <= 0)
ok = true;
mp[bl - a[j]]--;
}
}
if(ok)
continue;
for(int j = 0; j < n + k; j++){
if((mask >> j) % 2 != 0)
bl = bl;
else
cout << a[j] << ' ';
}
cout << endl;
return 0;
}
}
for(int i = 0; i < n + 1; i++){
ll sum2 = sum - a[i];
ll mn = a[0];
if(i == 0)
mn = a[1];
ll mx = a[n + k - 1];
if(i == n + k - 1)
mx = a[n + k - 2];
ll bl = sum2 / (n / 2);
if(sum2 % (n / 2) != 0)
continue;
if(mn + mx < bl || mx >= bl)
continue;
for(int j = 0; j < n + k; j++){
if(j == i)
continue;
cout << a[j] << ' ';
}
cout << endl;
return 0;
}
return 0;
}
# | 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... |