結果
| 問題 |
No.885 アマリクエリ
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-04-24 12:30:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 969 bytes |
| コンパイル時間 | 216 ms |
| コンパイル使用メモリ | 82,336 KB |
| 実行使用メモリ | 155,008 KB |
| 最終ジャッジ日時 | 2025-04-24 12:32:28 |
| 合計ジャッジ時間 | 9,850 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 8 TLE * 2 -- * 9 |
ソースコード
import bisect
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
N = int(data[idx])
idx += 1
A = list(map(int, data[idx:idx+N]))
idx += N
Q = int(data[idx])
idx += 1
X = list(map(int, data[idx:idx+Q]))
current_sum = sum(A)
sorted_list = sorted(A)
for xi in X:
pos = bisect.bisect_left(sorted_list, xi)
elements = sorted_list[pos:]
if not elements:
print(current_sum)
continue
sum_ge = sum(elements)
sum_mod = sum(a % xi for a in elements)
current_sum = current_sum - sum_ge + sum_mod
# Remove elements from the list
del sorted_list[pos:]
# Insert the new elements
for a in elements:
mod = a % xi
if mod > 0:
bisect.insort(sorted_list, mod)
print(current_sum)
if __name__ == "__main__":
main()
qwewe