VJ_Stones _优先队列

Stones

 

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

struct AA
{
    int pos,dis;
    friend bool operator < ( const AA& a,const AA& b )
    {
        return ( b.pos == a.pos ) ? ( b.dis < a.dis ) : ( b.pos < a.pos ) ;
    }
}in;
priority_queue<AA> q;

int main()
{
    int t,n,judge,sum;
    
    while( cin>>t )
        while( t-- )
        {
            cin>>n;
            while( n-- )
            {
                cin>>in.pos>>in.dis;
                q.push( in );
            }
            judge=sum=0;

            while( q.size() )
            {
                judge++;
                sum=q.top().pos;
                if( judge&1 )
                {
                    in.pos=q.top().pos+q.top().dis;
                    in.dis=q.top().dis;
                    q.pop();
                    q.push( in );
                }
                else q.pop();
            }
            cout<<sum<<endl;
        }
    return 0;
}

猜你喜欢

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