VJ_Stones_priority_queue_pair

//
// #include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<utility>		// pair
#include<functional>	// greater
using namespace std;

int main()
{
    int t,n,a,b,f;

    while( cin>>t )
    {
        while( t-- )
        {
            priority_queue< pair<int,int>,vector< pair<int,int> >,greater< pair<int,int> > > q;
            pair<int,int> tt;

            cin>>n;
            while( n-- )
            {
                cin>>a>>b; q.push( make_pair( a,b ) );
            }

            f=-1;
            while( !q.empty() )
            {
                tt=q.top(); q.pop();

                f=(f+1)%2;
                if( f ) continue;
                tt.first+=tt.second;
                q.push( tt );
            }
            cout<<tt.first<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/124645435