問題一覧 > 通常問題

No.2622 Dam

レベル : / AI推定難易度 : 1000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 158
作問者 : 👑 AngrySadEight / テスター : 👑 loop0919 zeta7532
お気に入りにしたユーザー ProblemId : 10499 / 自分の提出
問題文最終更新日: 2024-01-10 03:06:24
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 417 (順位表) の他の問題:

Problem Statement

There is a dam with capacity $V$ [L]. At time $t=0$ [s], the amount of water stored in this dam was $X$ [L].

Water flows out of this dam at a constant pace. Specifically, the amount of water decreases at a rate of $F_o$ [L] per second.

In addition, rain falls on this dam at specific times, and water flows in at a constant pace. Specifically, at times expressible as $kQ \leq t \leq kQ + R$ using a non-negative integer $k$, the amount of water increases at a rate of $F_i$ [L] per second (during this period, inflow and outflow occur simultaneously). At all other times, no inflow occurs.

When the amount of water stored in this dam becomes greater than the capacity, we say that the dam overflows. When the amount of water stored becomes $0$, we say that the dam runs dry.

Which happens first: the dam overflowing or the dam running dry?

Print Overflow if overflowing happens first, and Zero if running dry happens first. However, if neither of them happens by time $t = 10^{100}$ [s], print Safe.

You are given $T$ test cases; answer each of them.

Constraints

  • All input values are integers.
  • $1 \leq T \leq 1000$
  • $1 \leq X \leq V \leq 10^{18}$
  • $1 \leq F_o, F_i \leq 10^9$
  • $1 \leq R < Q \leq 10^9$

Input

The input is given from standard input in the following format. Here, $case_i$ denotes the $i$-th test case.

$T$
$case_1$
$case_2$
$\vdots$
$case_T$

Each case is given in the following format.

$V$ $X$ $F_o$ $F_i$ $Q$ $R$

Output

Print $T$ lines. On the $i$-th line, for the $i$-th test case, print Overflow if the dam overflowing happens first, Zero if the dam running dry happens first, and Safe if neither of them happens.

Sample

Sample 1
Input
3
10 5 3 5 3 2
10 5 3 4 3 2
10 5 2 4 4 2
Output
Overflow
Zero
Safe

The $1$st test case proceeds as follows.

  • From $t = 0$ to $t = 2$, inflow and outflow occur simultaneously, and the amount of water in the dam at $t = 2$ becomes $5 + 5 \times 2 - 3 \times 2 = 9$.
  • From $t = 2$ to $t = 3$, only outflow occurs, and the amount of water in the dam at $t = 3$ becomes $9 - 3 \times 1 = 6$.
  • From $t = 3$ to $t = 5$, inflow and outflow occur simultaneously, and the amount of water in the dam at $t = 3$ becomes $6 + 5 \times 2 - 3 \times 2 = 10$.
  • From $t = 5$ to $t = 6$, only outflow occurs, and the amount of water in the dam at $t = 6$ becomes $10 - 3 \times 1 = 7$.
  • From $t = 6$ to $t = 8$, inflow and outflow occur simultaneously. Here, at $t = 7.5$, the amount of water in the dam exceeds $10$, so the dam overflows.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。