結果
| 問題 | No.3527 Minimum Abs Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-04 23:43:11 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 828 ms / 2,000 ms |
| コード長 | 812 bytes |
| 記録 | |
| コンパイル時間 | 514 ms |
| コンパイル使用メモリ | 85,248 KB |
| 実行使用メモリ | 152,172 KB |
| 最終ジャッジ日時 | 2026-05-04 23:43:26 |
| 合計ジャッジ時間 | 14,212 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
from functools import cmp_to_key
def compare_frac(p1, p2):
b1, a1 = p1
b2, a2 = p2
v1 = b1 * a2
v2 = b2 * a1
if v1 < v2: return -1
if v1 > v2: return 1
return 0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mod = 10**9 + 7
C = []
total_weight = 0
for i in range(N):
if A[i] == 0:
continue
ai, bi = A[i], B[i]
if ai < 0:
ai, bi = -ai, -bi
C.append((bi, ai))
total_weight += ai
C.sort(key=cmp_to_key(compare_frac))
current_weight = 0
ans_b, ans_a = 0, 1
for b, a in C:
current_weight += a
if current_weight * 2 >= total_weight:
ans_b, ans_a = b, a
break
print((ans_b * pow(ans_a, -1, mod)) % mod)