#P2339. [USACO04OPEN] Turning in Homework G
[USACO04OPEN] Turning in Homework G
Description
Bessie has assignments to turn in, after which she will take the bus home with her classmates.
All teachers’ classrooms are arranged along a corridor of length . They accept assignments only after class, and turning them in takes no time. Bessie starts at position . You are given each classroom’s position and the position of the corridor exit (bus stop). For every unit of distance she walks, she spends 1 minute. Compute the earliest time by which she can finish turning in all assignments and reach the exit.
Input Format
The first line contains three integers , , and ().
Lines through : on the -th line, there are two integers and ().
denotes the position of the corridor exit.
is the position where the -th assignment must be turned in.
is the dismissal time of the teacher for that subject (the one who accepts this assignment) at that position.
Output Format
Output a single integer, the minimum time for Bessie to finish turning in all assignments and reach the exit.
4 10 3
8 9
4 21
3 16
8 12
22
Hint
In the sample, she walks to coordinate 8, turns in one assignment at minute 9, waits until minute 12 to turn in another, then walks to coordinate 4 to turn in, and finally goes to coordinate 3 to turn in the last assignment, which is also the bus stop location, for a total of 22 minutes.
Translated by ChatGPT 5
京公网安备 11011102002149号