Positive
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk gave Marichka 2 rows of candies. There are \(n\) candies in the first row and \(m\) in the second. Each candy has its own taste level. Unfortunately, some candies turned out to be tasteless, so their taste level can be negative.
Marichka wants to eat all the candies. To do this, she chooses the leftmost candy from the first row or the leftmost candy from the second row of her choice and eats it. Marichka continues this until she eats all the candies.
Initially, Marichka’s satisfaction level is 0. After each candy, her satisfaction level changes by the taste level of the candy. Marichka knows the taste levels of all the candies. Now she is wondering if she can eat the candies in such an order that her satisfaction level is never negative.
Input
The first line contains 2 integers \(n\) and \(m\) — the number of candies in the first and second row respectively. The second line contains \(n\) integers \(a_i\) — the taste levels of the candies in the first row from left to right. The third line contains \(m\) integers \(b_i\) — the taste levels of the candies in the second row from left to right.
Output
Print TAK if Marichka can eat all the candies so that
her satisfaction level never becomes negative, and NI if
Marichka cannot do this.
Constraints
\(1 \le n, m \le 2 \cdot 10^5\),
\(-10^9 \le a_i, b_i \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 4 4 4 7 -17 2 -10 8 -3 20 | TAK |
| Input (stdin) | Output (stdout) |
|---|---|
| 2 1 4 -47 7 | NI |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|