hdu1896 点击打开链接
#include"iostream"
#include"cstdio"
#include"cstdlib"
#include"cstring"
#include"queue"
using namespace std;
typedef struct node
{
int pos;
int weight;
}point;
struct cmp
{
bool operator()(const point a,const point b)
{
if(a.pos!=b.pos) return a.pos>b.pos; //>后置
else return a.weight>b.weight; //>后置
}
};
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
priority_queue<node,vector<node>,cmp> q;
point stone;
while(n--)
{
cin>>stone.pos>>stone.weight;
q.push(stone);
}
stone=q.top();
bool is=1;
while(!q.empty())
{
if(is==1)
{
stone=q.top();
stone.pos+=stone.weight;
q.push(stone);
q.pop();
}
else
{
stone=q.top();
q.pop();
}
is=!is;
}
cout<<stone.pos<<endl;
}
return 0;
}