結果
| 問題 | No.3527 Minimum Abs Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-26 02:16:00 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,597 bytes |
| 記録 | |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 85,560 KB |
| 実行使用メモリ | 153,792 KB |
| 最終ジャッジ日時 | 2026-05-26 02:16:19 |
| 合計ジャッジ時間 | 15,249 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 20 |
ソースコード
# https://yukicoder.me/problems/no/3527
from functools import cmp_to_key
MOD = 10 ** 9 + 7
# 比較関数
def compare_items(a, b):
if a[0] * b[1] > b[0] * a[1]:
return 1
elif a[0] * b[1] < b[0] * a[1]:
return -1
else:
return 0
def main():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
array = []
th = 0
for i in range(N):
a = A[i]
b = B[i]
if abs(a) != 0:
array.append((b, a))
else:
th += abs(b)
sorted_array = sorted(array, key=cmp_to_key(compare_items))
sum_a = -sum(A)
sum_b = -sum(B)
# x < array[0]
answers = [(sum_a, sum_b, sorted_array[0])]
b0, a0 = sorted_array[0]
sum_a += 2 * a0
sum_b += 2 * b0
for i in range(1, len(array)):
if sum_a < 0:
answers.append((sum_a, sum_b, sorted_array[i]))
else:
answers.append((sum_a, sum_b, sorted_array[i - 1]))
b0, a0 = sorted_array[i]
sum_a += 2 * a0
sum_b += 2 * b0
# array[-1] <= x
answers.append((sum_a, sum_b, sorted_array[-1]))
ans = None
ans_x = None
for sum_a, sum_b, x in answers:
y = (sum_a * x[0] - x[1] * sum_b + x[1] * th, x[1])
if ans is None:
ans = y
ans_x = x
else:
if compare_items(ans, y) == 1:
ans = y
ans_x = x
answer = ans_x[0] * pow(ans_x[1], MOD - 2, MOD)
answer %= MOD
print(answer)
if __name__ == "__main__":
main()