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

Правка en1, от 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://codeforces.net/problemset/problem/1512/D

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

Теги greedy, constructive algorithms, data structures, *1200

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Aayuushh19 2022-08-23 18:17:46 1024 Initial revision (published)