International Irregularities
Time limit3sMemory limit1024 MB
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 -value to each country based on its infection rate. A higher -value means a higher infection rate.
Each country asks tourists to quarantine when the country they just came from has an -value well above its own. Specifically, when travelling from country to country , the tourist must quarantine for days if .
Archaeologists found evidence of tourists travelling between 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 , , and (, , ), the number of countries, the number of tourists, and the maximum allowed difference between two -values when travelling to a country with a lower infection rate.
The second line contains integers (), the -value of each country.
The third line contains integers (), the quarantine time in days required when travelling to a country with a significantly lower -value.
The next lines each contain two integers and (, ), meaning a tourist departs from country with destination .
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.