Why this code is not working in online judge but working in my pc.

Revision en1, by Aayuushh19, 2022-08-23 18:17:46

void solve(){ ll n;cin>>n; vll b(n+2); FOR(i,0,n+2){ cin>>b[i]; } ll mx = *max_element(all(b)); sort(b.rbegin(),b.rend());

vll a;
ll c=0;
FOR(i,1,n+3){
    if(b[i]<=mx and c<n){
       a.pb(b[i]);
       mx-=b[i];
        c++;
    }
}
// dbg(a);
if(sz(a)!=n){
    sort(all(b));
    dbg(b);
    ll m = *max_element(all(b));
    vll temp;
    FOR(i,0,n){
        temp.pb(b[i]);
    }
    dbg(temp);
    if(accumulate(all(temp),0)!=m){
        cout<<-1<<endl;
        return;
    }
    for(auto i:temp){
        cout<<i<<" ";
    }
    cout<<endl;
}
else{
    for(auto i:a){
        cout<<i<<" ";
    }
    cout<<endl;
}

}

https://mirror.codeforces.com/problemset/problem/1512/D

Why this code is not working in online judge but working in my pc.

Tags greedy, constructive algorithms, data structures, *1200

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Aayuushh19 2022-08-23 18:17:46 1024 Initial revision (published)