Uniform Sum

AtCoder
IDarc195_b
Time5000ms
Memory256MB
Difficulty
There are two sequences $A=(A_1,\dots,A_N)$ and $B=(B_1,\dots,B_N)$. You can perform the following three types of operations any number of times in any order: * Choose an index $i$ such that $A_i = -1$, and replace $A_i$ with any non-negative integer. * Choose an index $i$ such that $B_i = -1$, and replace $B_i$ with any non-negative integer. * Rearrange the elements of sequence $A$ in any order. Determine whether it is possible, after these operations, for all elements of $A$ and $B$ to be non-negative and satisfy $A_1 + B_1 = A_2 + B_2 = \dots = A_N + B_N$. ## Constraints * $2 \leq N \leq 2000$ * $-1 \leq A_i \leq 10^9$ * $-1 \leq B_i \leq 10^9$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\ldots$ $A_N$ $B_1$ $B_2$ $\ldots$ $B_N$ [samples]
Samples
Input #1
4
2 0 -1 3
3 -1 4 2
Output #1
Yes

Consider the following operations:

*   Replace $A_3$ with $1$.
*   Replace $B_2$ with $1$.
*   Rearrange $A$ to $(1,3,0,2)$.

After these operations, $A = (1,3,0,2)$ and $B = (3,1,4,2)$: all elements of $A$ and $B$ are non-negative, and $A_1+B_1 = A_2+B_2 = A_3+B_3 = A_4+B_4 = 4$ is satisfied.
Input #2
3
1 2 3
1 2 4
Output #2
No

No matter how you perform the operations, it is impossible to satisfy $A_1+B_1 = A_2+B_2 = A_3+B_3$.
Input #3
3
1 2 -1
1 2 4
Output #3
No
API Response (JSON)
{
  "problem": {
    "name": "Uniform Sum",
    "description": {
      "content": "There are two sequences $A=(A_1,\\dots,A_N)$ and $B=(B_1,\\dots,B_N)$. You can perform the following three types of operations any number of times in any order: *   Choose an index $i$ such that $A_i =",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc195_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are two sequences $A=(A_1,\\dots,A_N)$ and $B=(B_1,\\dots,B_N)$. You can perform the following three types of operations any number of times in any order:\n\n*   Choose an index $i$ such that $A_i =...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments