Dot Product

AtCoder
IDarc200_a
Time3000ms
Memory256MB
Difficulty
You are given sequences of positive integers of length $N$: $A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N)$. Determine whether there exists an integer sequence $X=(X_1,X_2,\ldots,X_N)$ that satisfies all the following conditions, and if it exists, find one. * $-10^8\le X_i\le 10^8$ $(1\le i\le N)$ * $\displaystyle \sum_{i=1}^N A_iX_i > 0$ * $\displaystyle \sum_{i=1}^N B_iX_i < 0$ You are given $T$ test cases, so find the answer for each. ## Constraints * $1\le T\le 2\times 10^5$ * $1\le N\le 2\times 10^5$ * $1\le A_i,B_i\le 10^5$ * The sum of $N$ over all test cases is at most $2\times 10^5$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $T$ $\text{case}_1$ $\text{case}_2$ $\vdots$ $\text{case}_T$ Each test case is given in the following format: $N$ $A_1$ $A_2$ $\ldots$ $A_N$ $B_1$ $B_2$ $\ldots$ $B_N$ [samples]
Samples
Input #1
3
3
3 1 4
1 5 1
3
4 4 4
7 7 7
4
20 25 6 15
31 41 59 26
Output #1
Yes
4 -5 1
No
Yes
45 -10 -40 11

For the first test case, if we set $X=(4,-5,1)$, then

*   $\displaystyle \sum_{i=1}^3 A_iX_i=3\times 4+1\times (-5)+4\times 1=11>0$
*   $\displaystyle \sum_{i=1}^3 B_iX_i=1\times 4+5\times (-5)+1\times 1=-20<0$

which satisfies the conditions. Other examples that satisfy the conditions include $X=(3,-3,1)$ and $X=(27,-40,22)$.
API Response (JSON)
{
  "problem": {
    "name": "Dot Product",
    "description": {
      "content": "You are given sequences of positive integers of length $N$: $A=(A_1,A_2,\\ldots,A_N),B=(B_1,B_2,\\ldots,B_N)$. Determine whether there exists an integer sequence $X=(X_1,X_2,\\ldots,X_N)$ that satisfies ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc200_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given sequences of positive integers of length $N$: $A=(A_1,A_2,\\ldots,A_N),B=(B_1,B_2,\\ldots,B_N)$.\nDetermine whether there exists an integer sequence $X=(X_1,X_2,\\ldots,X_N)$ that satisfies ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments