问题 H: Teyberrs

内存限制:128 MB 时间限制:8 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Teyberrs is a paradise for birds to live in. Assume you are a bird in Teyberrs, you are now flying somewhere like the game ''Flappy Bird''. You start flying at (0,s), and every time when you are at (x1,y) (1xn), you must fly to either (x,y1) with cost ax or(x,y+1) with cost bx. Like the map in ''Flappy Bird'', you can not hit obstacles at (x,y) where y<lx or y>rx.

You will be given q queries. In each query, you will be given two integers x and y. Assume your target is at (x,y), can you find the path with the minimum cost, or determine it is impossible?

输入格式

The first line contains a single integer T (1T200), the number of test cases. For each test case:

The first line of the input contains three integers nq and s (1n,q200,0001sn), denoting the size of the map, the number of queries, and the start point.

In the next n lines, the i-th line contains four integers aibili and ri (1ai,bi1e91lirin).

In the next q lines, the i-th line contains two integers x and y (1x,yn), describing a target point.

It is guaranteed that the sum of all n is at most 1,000,000, and the sum of all q is at most 1,000,000

输出格式

For each query, print a single line containing an integer, denoting the minimum total cost. When it is impossible to reach the target, please print ''-1'' instead.

输入样例 复制

1
3 9 2
1 2 1 3
3 1 2 3
4 3 1 2
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

输出样例 复制

1
-1
2
-1
2
-1
6
-1
-1

分类标签