B. The Corridor or There and Back Again
由题意可知,对于每一个di和si,必须要在进入房间di的si之后离开这个房间,即最迟要在第一次进入该房间的si秒后反向通过该房间回到原点,所以只要计算出使每个条件都符合的最大经过房间数就可以求出答案。
\[Ans=\min \limits_{1≤i≤n}(d_i+\lfloor(s_i-1)/2\lfloor)
\]
代码
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
const ll N = 110, inf = 0x7f7f7f7f;
ll t;
ll n;
PII a[N];
signed main()
{
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while(t--)
{
cin >> n;
ll now = inf;
for(ll i = 0;i < n;i++)
{
cin >> a[i].first >> a[i].second;
now = min(now, a[i].first + ((a[i].second - 1) / 2));
}
cout << now << endl;
}
return 0;
}