This page is still under construction.

Parts of this page are still being built. What you see may change.

Mario Kart

Time limit1sMemory limit128 MB

Summary
Move between stations when a subset of coins meets the cost limit and matches the distance, and find the fewest moves from the first to the last station.
Level

Medium6 of 10

Topics
Dynamic programming, Graph, BFS
Solved
No attempts yet

Problem

A new version of the Mario game is out, and this one is a kart racing game. Write a program that finds the strategy for finishing each level in the fewest moves.

The track of a level is an infinite straight line with stations at some of its points. Every station sits at an integer position. You start at the station with the smallest position and must reach the station with the largest position in as few moves as possible.

You can move between two stations in one move if you have enough boost coins for it. The destination does not have to be the next station over, and you may go back to a station with a smaller position. Each level gives you a set of boost coins, and every coin has a cost and a power value. For one move you can pick any subset of the coins, but a single coin cannot be used twice in the same move. Coins are permanent, so you can use them again in later moves of the same level.

To make a move you must pick a subset of the boost coins whose total cost is at most LL and whose total power is exactly the absolute difference between the positions of the two stations. If no such subset exists, you cannot move between those two stations directly.

You are given the configuration of several levels. For each one, find the minimum number of moves that finishes it, or report that finishing it is impossible.

Input

The first line contains a single integer TT, the number of test cases. (1≤T≤1001 \le T \le 100)

The first line of each test case contains three integers separated by single spaces: the number of stations NN, the number of boost coins MM, and the largest total cost allowed in one move LL. (2≤N≤1002 \le N \le 100, 1≤M≤1001 \le M \le 100, 1≤L≤10001 \le L \le 1000)

The second line contains NN distinct positive integers separated by single spaces, the positions of the stations. They are not necessarily sorted, and each position is at most 10001000.

Each of the next MM lines contains two integers separated by a single space, the cost CC and the power value VV of one coin. (1≤C,V≤1001 \le C, V \le 100)

Output

For each test case, print one line with a single integer. Print -1 if there is no way to get from the station with the smallest position to the station with the largest position, otherwise print the minimum number of moves.

Hint

Take a level whose station positions are 3, 1, 6, with L=4L = 4 and two coins, one of cost 3 and power 2 and one of cost 3 and power 3. You start at 1 and must end at 6, so two moves are needed. The power 2 coin takes you from 1 to 3, and the power 3 coin takes you from 3 to 6. Going from 1 straight to 6 would need both coins at once, and their total cost of 6 is over the limit of 4.

Examples1

  1. Example 1

    Input
    2
    3 2 4
    3 1 6
    3 2
    3 3
    3 1 4
    1 3 6
    3 2
    
    Expected output
    2
    -1