The Corridor or There and Back Again
C o d e Code Code
#include <bits/stdc++.h>
#define int long long
#define sz(a) ((int)a.size())
using namespace std;
using PII = pair<int, int>;
using i128 = __int128;
const int N = 2e5 + 10;
int n;
int a[N];
void solve() {
cin >> n;
for (int i = 1; i <= 200; i ++ ){
a[i] = 1e18;
}
for (int i = 1; i <= n; i ++) {
int d, s; cin >> d >> s;
a[d] = min(a[d], s);
}
cout << " ";
int res = 410;
for (int i = 1; i <= 200; i ++) {
if (a[i] != 1e18) { // 这个地方存在陷阱
res = min(res, i - 1 + (a[i] + 1) / 2);
/*
我一开始用的是i - 1 + a[i] / 2,
但发现输出不对,就根据样例觉得应该是
i - 1 + (a[i] + 1) / 2。
这种比较模糊的边界问题很麻烦,
很多时候都需要根据样例确定题目意思到底是什么。
*/
}
}
cout << max(res, 1ll) << "\n";
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
cin >> T; cin.get();
while (T --) solve();
return 0;
}