Logo
(追記) (追記ここまで)

32067번 - Game Show 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB37282775.000%

문제

You are hosting a game show. In your game show, there is a circular disk divided into $N$ regions, numbered from 1ドル$ to $N$ in clockwise order. For each region $i$ (1ドル ≤ i ≤ N - 1$), region $i + 1$ is located to the next of region $i,ドル and region 1ドル$ is located to the next of region $N$.

There are $Q$ independent rounds. In each round, the player starts from region $S$ and the target is at region $T$. For each $i$ such that 1ドル ≤ i ≤ N,ドル the player can move from region $i$ to region $i + 1$ (or to region 1ドル$ if $i = N$) with a penalty of $A_i$. Similarly, the player can move from region $i + 1$ (or from region 1ドル$ if $i = N$) to region $i$ with a penalty of $B_i$. 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 $N$ $Q$ (3ドル ≤ N ≤ 200,円 000$; 1ドル ≤ Q ≤ 200,円 000$) representing the number of regions and the number of rounds, respectively.

The next line contains $N$ integers $A_i$ ($-10^9 ≤ A_i ≤ 10^9$) representing the penalty to move from region $i$ to region $i + 1,ドル or to region 1ドル$ if $i = N$. The next line contains $N$ integers $B_i$ ($-10^9 ≤ B_i ≤ 10^9$) representing the penalty to move from region $i + 1,ドル or from region 1ドル$ if $i = N,ドル to region $i$.

Each of the next $Q$ lines contains two integers $S$ $T$ (1ドル ≤ S, T ≤ N$) 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.

제한

예제 입력 1

4 4
2 3 -4 3
1 2 7 -1
1 3
3 1
1 4
1 1

예제 출력 1

5
-1
-1
0

In round 1ドル,ドル the path 1ドル → 2 → 3$ has a penalty of 2ドル + 3 = 5$.

In round 2ドル,ドル the path 3ドル → 4 → 1$ has a penalty of $(-4) + 3 = -1$. This path has lesser penalty than path 3ドル → 2 → 1,ドル which has a penalty of 2ドル + 1 = 3$.

In round 3ドル,ドル the path 1ドル → 4$ has a penalty of $-1$.

예제 입력 2

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

예제 출력 2

flawed
flawed
flawed

For all rounds, the player can go to region 2ドル,ドル then repeatedly travel back and forth in regions 2ドル$ and 3ドル$ to reduce the penalty by 1ドル$ infinitely many times.

예제 입력 3

6 2
-6 8 -3 5 -9 4
9 -2 8 -4 12 -1
2 6
3 3

예제 출력 3

flawed
flawed

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2022 ICPC Asia Jakarta Regional Contest M번

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2023 ICPC Asia Jakarta Regional Contest 연습 세션 PB번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /