Tiredness

2.4

19 votes
Hard, Basic Math, Mathematics, Mathematics
Problem

You are required to go from a point (xs,ys) to (xf,yf). You are getting tired at the rate of c0 per meter while you are walking. There is a rectangular canopy that is available on the way that reduces the exhaustion of energy. The ith canopy is installed from point (x1[i],y1[i]) to (x2[i],y2[i]). The rate at which you are getting tired when you are under the canopy is ci per meter.

If you are changing your direction of movement, then you become d unit tired. Your task is to minimize the value of your tiredness.

Input format

  • First line: Two space-separated integers n (1n100 000) and d (1d100)
  • Second line: Five space-separated integers, xs ys xf yf c0
  • Next n lines: Five space-separated integers, x1[i] y1[i] x2[i] y2[i] c[i]

Note: It is guaranteed all coordinates are in the range [1,107] and 1c[i]c0109.

Output format

The format of the output is as follows:

  • First line: Print m that denotes the number of partitions of your path (1m105).
  • Next m lines: Print information about that partition from_xi from_yi to_xi to_yi throughi in each line.

Note

  • Here, throughi denotes the index of the canopy under which you are walking or 0 if you are walking without the canopy. 
  • Your score will be calculated automatically by the explained path.
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

No descreption.

Editor Image

?