Game Show
시간 제한2초메모리 제한1024 MB
방향 간선 가중치가 있는 원형 그래프에서 S에서 T까지의 최단 비용을 구하거나, 음수 사이클 때문에 비용이 무한히 작아질 수 있으면 flawed를 출력한다.
문제
You are hosting a game show. In your game show, there is a circular disk divided into regions, numbered from to in clockwise order. For each region (), region is located to the next of region , and region is located to the next of region .
There are independent rounds. In each round, the player starts from region and the target is at region . For each such that , the player can move from region to region (or to region if ) with a penalty of . Similarly, the player can move from region (or from region if ) to region with a penalty of . Note that the penalty can be negative.
The goal of each round is to find the minimum total penalty required to reach the target. However, you noticed that it is possible for the player to abuse the game to reach the target with a penalty of . Such round is called flawed.
For each round, determine if the round is flawed or not. If the round is not flawed, determine the minimum penalty to reach the target.
입력
Input begins with two integers (; ) representing the number of regions and the number of rounds, respectively.
The next line contains integers () representing the penalty to move from region to region , or to region if . The next line contains integers () representing the penalty to move from region , or from region if , to region .
Each of the next lines contains two integers () representing the start region and target region of each round, respectively.
출력
For each round, if the round is flawed, then output flawed in a single line. Otherwise, output an integer in a single line, representing the minimum penalty to reach the target.