Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mk make_pair
- #define fi first
- #define se second
- #define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
- using namespace std;
- typedef vector<int> vi;
- typedef pair<int,int> ii;
- typedef long long ll;
- typedef vector<bool> vb;
- const int N=200010;
- int n, v[N], b;
- int main(void) {
- ios::sync_with_stdio(false);
- cin >> n >> b;
- multiset<int> q;
- for (int i = 0; i<2*n; i++) {
- int x;cin>>x;
- q.insert(x);
- }
- vi ans;
- multiset<int>::reverse_iterator it = q.rbegin();
- vector<int> qq;
- while (!q.empty()) {
- int x = *q.rbegin();
- q.erase(q.find(x));
- auto itx = q.upper_bound(b-x-1);
- if (itx == q.begin()) {
- qq.pb(x);
- }
- else {
- itx--;
- ans.pb(x + *itx);
- q.erase(itx);
- }
- }
- sort(qq.begin(), qq.end());
- for (int i = qq.size()-1; i>=0; i-=2) {
- ans.pb(qq[i]+qq[i-1]-b);
- }
- sort(ans.rbegin(), ans.rend());
- for (int i = 0; i<ans.size(); i++)
- cout << ans[i] << " ";
- cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement