#BS0000410. Vượt qua sa mạc (Through the Desert)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Vượt qua sa mạc (Through the Desert)
Through the Desert
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
An explorer drives across a desert, starting at position 0 with a full fuel tank. Fuel consumption can change, leaks can appear, and the vehicle may encounter gas stations or mechanics.
The journey is described by the following events:
Fuel consumption n: from this position onward the engine uses litres per 100 km until the rate changes again.Leak: one additional puncture appears in the tank. Each active puncture loses 1 litre per kilometre; losses from several punctures add together.Gas station: refill the tank completely. Existing leaks are not repaired.Mechanic: repair all active punctures without adding fuel.Goal: the destination is reached and the journey ends.
Fuel is consumed while travelling between positions. Events at the same position are processed in input order. The vehicle may arrive with exactly zero fuel and process the event there. Find the smallest tank capacity allowing the vehicle to complete the journey without running out of fuel between positions.
Input
Each line describes an event: an integer , its distance in kilometres from the start, followed by one of the five event descriptions above. A Fuel consumption n event includes the integer parameter . The first line is 0 Fuel consumption n. The last line is d Goal, and there is exactly one Goal event.
Let be the number of event lines. The value is not supplied separately; read through the Goal line.
Output
Print one line giving the minimum tank capacity in litres with exactly three digits after the decimal point.
Subtasks
- Subtask 1 (20 points): ; ; in every
Fuel consumption nevent; the first line is0 Fuel consumption n, the last isd Goal, with no earlierGoal; each line contains exactly one valid event. OnlyFuel consumption nandGoaloccur. - Subtask 2 (30 points): ; ; in every
Fuel consumption nevent; the first line is0 Fuel consumption n, the last isd Goal, with no earlierGoal; each line contains exactly one valid event. NoGas stationevent occurs. - Subtask 3 (50 points): ; ; in every
Fuel consumption nevent; the first line is0 Fuel consumption n, the last isd Goal, with no earlierGoal; each line contains exactly one valid event.
Examples
Input
0 Fuel consumption 10
100 Goal
Output
10.000
Explanation
The engine uses 10 litres per 100 km. The trip is 100 km without other events, so exactly 10 litres are needed.
Input
0 Fuel consumption 5
100 Fuel consumption 30
200 Goal
Output
35.000
Explanation
The first 100 km use 5 litres and the next 100 km use 30 litres. With no refill, the capacity must be at least litres.
Input
0 Fuel consumption 20
10 Leak
25 Leak
25 Fuel consumption 30
50 Gas station
70 Mechanic
100 Leak
120 Goal
Output
81.000
Explanation
From km 0 to 10 the vehicle uses 2 litres; from 10 to 25 it uses litres; from 25 to 50 it uses litres. Total before refilling is 77.5 litres. After refilling, the next three intervals use 46, 9 and 26 litres, respectively, totaling 81. A capacity of 81 litres is necessary and sufficient.