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

· · 题解

\textmd{P12641 上学 题解}

这是本蒟蒻的第一篇题解,望通过qwq

using namespace std;

int main() { int n, x; // n -> 公交车数量, x -> 总时间限制 cin >> n >> x;

int ans = -1; // 初始化答案为 -1 (如果没有找到则直接输出-1)

for (int i = 0; i < n; ++i) {
    int s, t; // s -> 出发时间, t -> 行驶时间
    cin >> s >> t;

    if (s + t <= x) { // 如果能在 x 分钟内到达学校
        ans = max(ans, s); // 更新最晚出发时间 (用max是因为出发时间越早那么 ans 越大)
    }
}

cout << ans << endl; // 输出结果

return 0;

}