题解:P12641 [KOI 2024 Round 1] 上学

· · 题解

赶紧交一篇题解涨涨咕值。

按照题意,我们需要找出能让小明不迟到的所有公交车中找出最晚出发的一辆,所以我们挨个判断一下是否可以准时到达学校,在可以准时到达学校的公交车中找出最晚出发的一辆即可。

前面交了三次没过,结果发现忘记输入了。

Code

#include <bits/stdc++.h>
using namespace std;
int n, x, ans = -1;
int main() {
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        int s, t;
        cin >> s >> t;
        if (s + t <= x) {
            ans = max(ans, s);
        }
    }
    cout << ans;
    return 0;
}