优先队列
1 #include<stdio.h> 2 #include<queue> 3 using namespace std; 4 struct node 5 { 6 int p,d; 7 friend bool operator<(node a,node b) 8 { 9 if(a.p==b.p) return a.d>b.d; 10 return a.p>b.p; 11 } 12 }cur,next; 13 int main() 14 { 15 int t,n; 16 priority_queue<node>q; 17 scanf("%d",&t); 18 while(t--) 19 { 20 scanf("%d",&n); 21 int step=1; 22 while(n--) 23 { 24 scanf("%d %d",&cur.p,&cur.d); 25 q.push(cur); 26 } 27 while(!q.empty()) 28 { 29 cur=q.top(); 30 q.pop(); 31 if(step) 32 { 33 cur.p+=cur.d; 34 q.push(cur); 35 } 36 step=(step+1)%2; 37 } 38 printf("%d ",cur.p); 39 } 40 }