Under construction

Still being built. Things may change

International Irregularities

Time limit3sMemory limit1024 MB

Summary
Given countries with r-values and quarantine times, answer each query with the minimum days to travel from a start country to a destination.
Level

Hard8 of 10

Topics
Shortest path, Graph, Segment tree
Solved
No attempts yet

Problem

Long ago on a planet far, far away, a highly contagious virus caused a long-lasting pandemic.

Even so, people still wanted to travel between countries for their summer holidays. Before the pandemic, travel from any country to any other country took 1 full day. During the pandemic, however, some countries did not want travellers from areas with higher infection rates. They required those travellers to quarantine for a set number of days before they could continue their trip or start their holiday.

To keep things fair, an independent Bureau for Accurate Pandemic Classification assigned an rr-value to each country based on its infection rate. A higher rr-value means a higher infection rate.

Each country asks tourists to quarantine when the country they just came from has an rr-value well above its own. Specifically, when travelling from country ii to country jj, the tourist must quarantine for tjt_j days if ri>rj+mr_i > r_j + m.

Archaeologists found evidence of qq tourists travelling between nn countries. The start and destination of each tourist are known. Find the minimal travel time for each tourist.

Input

The first line contains three integers nn, qq, and mm (2≤n≤1052 \leq n \leq 10^5, 1≤q≤1051 \leq q \leq 10^5, 0≤m≤1090 \leq m \leq 10^9), the number of countries, the number of tourists, and the maximum allowed difference between two rr-values when travelling to a country with a lower infection rate.

The second line contains nn integers r1,…,rnr_1, \dots, r_n (0≤r1≤⋯≤rn≤1090 \leq r_1 \leq \dots \leq r_n \leq 10^9), the rr-value of each country.

The third line contains nn integers t1,…,tnt_1, \dots, t_n (0≤ti≤1090 \leq t_i \leq 10^9), the quarantine time in days required when travelling to a country with a significantly lower rr-value.

The next qq lines each contain two integers xx and yy (1≤x,y≤n1 \leq x, y \leq n, x≠yx \neq y), meaning a tourist departs from country xx with destination yy.

Output

For each tourist, in the order they appear in the input, print the minimal travel time in days from the departure country to the destination country, one per line.

Examples2

  1. Example 1

    Input
    5 4 1
    0 5 6 7 8
    3 4 1 5 10
    1 4
    4 1
    4 2
    5 2
    
    Expected output
    1
    4
    2
    3
    
  2. Example 2

    Input
    5 4 10
    0 8 20 25 30
    5 11 13 6 3
    5 1
    5 2
    5 3
    5 4
    
    Expected output
    6
    7
    1
    1