#P15628. [ICPC 2022 Jakarta R] Game Show
[ICPC 2022 Jakarta R] Game Show
Problem Description
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 Format
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.
Output Format
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.
4 4
2 3 -4 3
1 2 7 -1
1 3
3 1
1 4
1 1
5
-1
-1
0
4 3
1 2 -3 4
4 -3 2 1
1 1
2 4
3 1
flawed
flawed
flawed
6 2
-6 8 -3 5 -9 4
9 -2 8 -4 12 -1
2 6
3 3
flawed
flawed
Hint
Explanation for the sample input/output #1
In round , the path has a penalty of .
In round , the path has a penalty of . This path has lesser penalty than path , which has a penalty of .
In round , the path has a penalty of .
Explanation for the sample input/output #2
For all rounds, the player can go to region , then repeatedly travel back and forth in regions and to reduce the penalty by infinitely many times.