题目链接:hdoj 1896 Stones
题意:给你
n
个石头以及每个石头可以扔出去的距离,碰到第
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define PI acos(-1.0)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
void getmax(int &a, int b) {a = max(a, b); }
void getmin(int &a, int b) {a = min(a, b); }
void add(LL &x, LL y) { x += y; x %= MOD; }
struct cmp {
bool operator()(pii a, pii b) {
return a.fi != b.fi ? a.fi > b.fi : a.se > b.se;
}
};
priority_queue<pii, vector<pii>, cmp > Q;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t; cin >> t;
while(t--)
{
int n; cin >> n;
for(int i = 0; i < n; i++) {
int u, v;
cin >> u >> v;
Q.push(pii(u, v));
}
int id = 0; int ans = 0;
while(!Q.empty())
{
pii u = Q.top(); Q.pop();
++id;
ans = max(ans, u.fi);
if(id & 1) {
Q.push(pii(u.fi+u.se, u.se));
}
}
cout << ans << endl;
}
return 0;
}