시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB25171669.565%

문제

It is a lovely summer day, and Alice wants to do a day trip. She lives in Tampere, and wants to travel to Porvoo to enjoy the Old Town and the surrounding nature. Alice does not only love travelling, but also planning.

She has created a map of the most beautiful paths to Porvoo. On her trip she needs to visit $n$ cities in order, where Tampere is the first city and Porvoo is the last city. The cities are connected by roads, with each road connecting two consecutive cities, and there is always at least one road between each pair of consecutive cities.

When driving from one city to the next, Alice needs to choose which road to take. Some of these roads have a tarmac surface, while others are just gravel roads and some roads have bridges which will not support vehicles that are too heavy. For each road it is known how long it takes to traverse it and what is the maximal weight of vehicles that can safely drive on it.

Figure E.1: Illustration of the second sample input. The red path from Tampere to Porvoo is the optimal choice for a car of weight $31$.

Alice collects many different cars of different weights, but she is not sure yet which car she will use for the day trip. As she wants to enjoy as much time in Porvoo as possible, she wants you to help her find the minimal travel time for each car.

입력

The input consists of:

  • Two integers $n$ and $m$ $(2 \leq n \leq 10^5, n - 1 \leq m \leq 10^5)$, the number of cities and the number of connections, respectively. The cities are numbered from $1$ to $n$, Tampere is city $1$, and Porvoo is city $n$.
  • $m$ lines, each containing three integers $i$, $d$ and $c$ $(1 \leq i < n, 1 \leq d \leq 10^4, 1 \leq c \leq 10^6)$, which each describe a connection between city $i$ and city $i + 1$ which takes $d$ minutes to traverse and can can be used by vehicles of weight $c$ kilograms or less.
  • One integer $q$ $(1 \leq q \leq 10^5)$, the number of cars that Alice has collected.
  • $q$ lines, where the $i$th line contains one integer $w_i$ $(1 \leq w_i \leq 10^6)$, the weight of the $i$th car in kilograms.

There is at least one connection from city $i$ to city $i+1$ for each $i$ ($1 \le i < n$).

출력

Output $q$ lines, where the $i$th line describes the shortest time in minutes Alice needs to drive to get from Tampere to Porvoo with the $i$th car. If there is no feasible path for the $i$th car, output impossible.

예제 입력 1

2 2
1 100 300
1 1 30
5
400
500
300
20
1

예제 출력 1

impossible
impossible
100
1
1

예제 입력 2

5 7
1 200 30
2 200 31
3 200 32
4 200 33
1 5000 33
2 5000 33
3 5000 33
3
30
31
33

예제 출력 2

800
5600
15200

예제 입력 3

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

예제 출력 3

2
3
3

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2021 E번

  • 문제를 만든 사람: Andreas Grigorjew

채점 및 기타 정보

  • 이 문제의 채점 우선 순위는 2이다.