话说我是本题第一个提交代码的用户!
步入正题。
对于每辆公交车的出发时间 和行驶时间 ,我们需要确保 不超过规定的时间 。在满足这一条件的公交车中,我们选择出发时间 最大的那一辆。如果没有满足条件的公交车,则输出 。
依照上文进行模拟即可。
C++ 代码如下:
#include <bits/stdc++.h>
using namespace std;
int n, x, ans = -1, s, t;
int main()
{
cin >> n >> x;
while (n--)
{
cin >> s >> t;
if (s + t <= x) ans = max(s, ans);
}
cout << ans << endl;
return 0;
}