美文网首页
Codeforces Round #696 (Div. 2)

Codeforces Round #696 (Div. 2)

作者: burningrain | 来源:发表于2021-01-23 11:36 被阅读0次

C. Array Destruction
卡一个小细节,要把迭代器赋值给某一个数,不能直接这样用*it,我就一直卡在了13那个样例

#include<bits/stdc++.h>
using namespace std;
int a[3000];
int sum;
multiset<int > s1;
int n;
vector<pair<int,int> > s2;
bool _check(int x){
    s1.clear();
    s2.clear();
    sum=a[x]+a[2*n-1];
    s2.push_back({a[x],a[2*n-1]});
    int maxx=a[2*n-1];
    for(int i=0;i<2*n-1;i++){
        if(i!=x){
            s1.insert(a[i]);
        }
    }
    multiset<int >::iterator it,it2;
    for(int i=0;i<n-1;i++){
        it = s1.end();
        it--;
        int x = *it;
        int u = maxx-x;
        s1.erase(it);
        it2 = s1.lower_bound(u);
        int y=*it2;
        if(it2==s1.end()) return false;
        else if(y!=u) return false;
        else{
            s2.push_back({x,u});
            maxx = max(u,x);
            s1.erase(it2);
        }

    }
    return true;
}
bool check(){
    for(int i=0;i<2*n-1;i++){
        if(_check(i)){
            return true;
        }
    }
    return false;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        // int n;
        cin>>n;
        memset(a,0,sizeof(a));
        for(int i=0;i<2*n;i++){
            cin>>a[i];
        }
        sort(a,a+2*n);
        if(check()){
            cout<<"YES"<<endl;
            cout<<sum<<endl;
            for(auto y: s2){
                cout<<y.first<<" "<<y.second<<endl;
            }
        }else{
            // cout<<a[2*n-1]<<endl;
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

相关文章

网友评论

      本文标题:Codeforces Round #696 (Div. 2)

      本文链接:https://www.haomeiwen.com/subject/lpnyzktx.html