还是优先队列
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; #define maxn 100010 struct Node { int x,y,id; friend bool operator < (Node a,Node b) { if(a.x != b.x) return a.x > b.x; else if(a.y != b.y) return a.y > b.y; else return a.id < b.id; } } node[maxn]; priority_queue<Node>que; int main() { int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%d%d",&node[i].x,&node[i].y); node[i].id = i+1; que.push(node[i]); } int tot = 0,maxt = -9999; while(!que.empty()) { tot++; Node tmp = que.top(); que.pop(); if(tot & 1 == 1) { Node next = tmp; next.x = tmp.x + tmp.y; if(next.x > maxt) maxt = next.x; que.push(next); } } printf("%d\n",maxt); } return 0; }
时间: 2024-11-05 02:13:29