Aayuushh19's blog

By Aayuushh19, history, 2 years ago, In English
void solve(){
    ll n;cin>>n;
    ll flag =0;
    vll b(n+2);
    FOR(i,0,n+2){
    	cin>>b[i];
    }
    ll mx = *max_element(all(b));
    sort(b.begin(),b.end());
    ll sum = accumulate(all(b),0);
    sum = sum-b[n+1];
    ll s2 = sum-b[n];
    dbg(sum);
    dbg(s2);
    ll x=-1;
    for(ll i=0;i<n+1;i++){
        if(sum-b[i]==mx){
            x=i;
            break;
        }
    }
    if(x==-1){
        ll s=0;
        for(ll i=0;i<n;i++){
            s+=b[i];
        }
        dbg(s);
        if(s==b[n]){
            flag=1;
            for(ll i=0;i<n;i++){
                cout<<b[i]<<" ";
            }
            cout<<endl;
        }
    }
    else{
        flag =1;
        for(ll i=0;i<n+1;i++){
            if(i!=x){
                cout<<b[i]<<" ";
            }
        }
        cout<<endl;
    }
    if(flag==0) cout<<-1<<endl;
   

}

https://codeforces.me/contest/1512/problem/D

  • Vote: I like it
  • -18
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You should try to make your code readable if you are asking for help.

Currently with no newlines, it is not.