QOJ.ac

QOJ

时间限制: 1 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#18118. The Reason Why Hobanwoo Was Late for School 8

统计

It is now time for Hobanwoo to return to the beloved Kyungpook National University. However, there is one problem: while it is easy to come from Earth to the otherworld, returning from the otherworld to Earth is difficult.

In the universe, which can be represented as a 2D coordinate plane, there are $N$ planets numbered from $1$ to $N$, excluding the otherworld.

For each $i$ such that $1 \le i \le N$, planet $i$ is located at $(x_{i}, y_{i})$ in the first quadrant and has a pair of positive integers $a_{i}$ and $b_{i}$. The $x$-coordinates $x_{i}$ of the planets from $1$ to $N$ form an increasing sequence.

Hobanwoo starts at the otherworld, which is planet $0$ at $(0, 0)$, and wants to reach planet $N$, where the portal to return to Earth is located, by passing through several planets.

When Hobanwoo is currently at planet $s$ and wants to go to planet $e$, he can do so if and only if $s < e \le \min(N, s+M)$ for a given positive integer $M < N$. The time taken is $a_{e}$ if planet $s$ is part of the convex hull of the set of planets $\{0, 1, \dots, e\}$, and $b_{e}$ otherwise.

Help Hobanwoo reach planet $N$ as quickly as possible so he does not arrive late for school!

Input

The first line contains two positive integers $N$ and $M$, separated by a space, where $1 \le M < N \le 200\,000$.

The next $N$ lines each contain $x_{i}, y_{i}, a_{i}, b_{i}$ for planets $1$ through $N$, separated by spaces, where $1 \le x_{i}, y_{i}, a_{i}, b_{i} \le 10^{9}$.

The sequence $x_{1}, x_{2}, x_{3}, \dots, x_{N}$ is strictly increasing.

Output

Output the minimum time required for Hobanwoo to travel from the otherworld to planet $N$.

Examples

Input 1

4 2
102180138 230636159 100 100
261562641 590386782 100 100
300000000 100000000 100 100
408720552 922544636 100 1

Output 1

101

Input 2

1 1
1 2 2 1

Output 2

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.