Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- vector<int> b, c;
- for(auto e: a)
- {
- if(e%2) b.pb(e);
- else c.pb(e);
- }
- if(b.size()%2)
- {
- cout<<-1<<"\n";
- continue;
- }
- vector<int> ans(n);
- int pos = 0;
- sort(b.rbegin(), b.rend());
- sort(c.rbegin(), c.rend());
- for(int i=0; i<b.size()/2; i++)
- {
- int x = b[i] + b[b.size()-i-1];
- x /= 2;
- ans[pos] = x;
- ans[pos+n/2] = b[i]-x;
- pos++;
- }
- for(int i=0; i<c.size()/2; i++)
- {
- int x = c[i] + c[c.size()-i-1];
- x /= 2;
- ans[pos] = x;
- ans[pos+n/2] = c[i]-x;
- pos++;
- }
- for(auto e: ans)
- cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment