Where it is crashing?

Revision en2, by Aayuushh19, 2022-09-12 07:32:16
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://mirror.codeforces.com/contest/1512/problem/D

Tags maths, implementations, *1200

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Aayuushh19 2022-09-12 07:32:16 23 Tiny change: '\n~~~~~\nvoi' -> '~~~~~\nvoi'
en1 English Aayuushh19 2022-08-23 21:48:10 1003 Initial revision (published)