Comment

avatar username

anyone pls help me implement the m = 0 case for D.

My logic that I thought during contest was something like storing the elfs in multiset and then attacking largest and second largest and thus second largest dies and largest hurts. So, i remove(both) and insert(the health after hurting) in multiset.

Any help will be appreciated

code :
      if(m == 0){
            vi fought(n, 0);

            multiset<pll> s;
            for(auto p : arr) {
                s.insert({p.sc, p.fs}); 
            }

            vctrpll fight;
            
            while(s.size() >= 2){
                auto it_max = prev(s.end());
                auto it_2nd = prev(it_max);

                if(!fought[it_2nd->second]){
                    fight.push_back({it_2nd->second, it_max->second});
                    fought[it_2nd->second] = 1;
                }
                else{
                    fight.push_back({it_max->second, it_2nd->second});
                    fought[it_max->second] = 1;
                }

                s.erase(it_max);
                s.erase(it_2nd);
                if(it_max->first - it_2nd->first > 0)
                s.insert({it_max->first - it_2nd->first,it_max->second});
            }

            cout << fight.size() << endl;
            for(auto it : fight){
                cout << it.fs << " " << it.sc << endl;
            }
            continue; 
        }

full code : 355403171

The actual rating of this user is 1360.

Original comment.

Statistics