問題一覧 > 通常問題

No.3527 Minimum Abs Sum

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 37
作問者 : yu23578 / テスター : Yoyoyo8128 aa36 Germanium32 GaLLium
お気に入りにしたユーザー ProblemId : 13120 / 自分の提出
問題文最終更新日: 2026-05-20 16:49:57
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. Show the original
聖光学院プログラミングコンテスト2026 day2 (順位表) の他の問題:

Problem Statement

You are given integer sequences $A,B$ of length $N$. For a rational number $x$, define the function $f(x)$ as follows. $$f(x) = \sum_{i=1}^N |A_i x - B_i|$$ Among the values of $x$ at which $f(x)$ attains its minimum, output the smallest $x$ modulo $\mathrm{mod} 10^9+7$.
It is guaranteed that such an $x$ exists and can be uniquely represented in $\mathrm{mod} 10^9+7$.

What $x\ \mathrm{mod} 10^9+7$ means when $x$ is a rational number In this problem, when the answer $x$ is expressed as an irreducible fraction $\frac{P}{Q}$, it is guaranteed that $Q \not\equiv 0 (\mathrm{mod} 10^9+7)$, so
the $R$ satisfying $R \times Q \equiv P (\mathrm{mod} 10^9+7), 0 \le R < 10^9+7$ is uniquely determined. Answer this $R$.

Constraints

  • $1 \le N \le 2 \times 10^5$
  • $|A_i|,|B_i| \le 10^9$
  • There exists an $i (1 \le i \le N)$ such that $A_i \neq 0$
  • When the answer $x$ is expressed as an irreducible fraction, its denominator is not a multiple of $10^9+7$
  • All input values are integers

Input

$N$
$A_1\ A_2\ A_3\ \cdots\ A_N$
$B_1\ B_2\ B_3\ \cdots\ B_N$

Output

Output the minimum $x$ satisfying the condition, in $\mathrm{mod} 10^9+7$. Print a newline at the end.

Sample

Sample 1
Input
3
1 1 1
1 1 -1
Output
1

We have $f(x) = |x-1| + |x-1| + |x+1|$. The minimum value $f(1) = 2$ is attained at $x = 1$, so output $1$.

Sample 2
Input
4
0 0 0 6
0 4 2 7
Output
166666669

Sample 3
Input
4
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
Output
1

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