結果

問題 No.3409 How Many Gift Boxes?
コンテスト
ユーザー titia
提出日時 2025-12-16 03:52:47
言語 Python3
(3.14.2 + numpy 2.4.0 + scipy 1.16.3)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 477 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 146 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 55,216 KB
最終ジャッジ日時 2025-12-17 21:19:15
合計ジャッジ時間 12,880 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from collections import Counter

mod=10**9+7

H,W=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ANS=0

A.sort()
B.sort()
S=[0]
for a in A:
    S.append(S[-1]+a)

ind=0
for b in B:
    while ind<len(A) and A[ind]<=b:
        ind+=1
    ANS+=S[ind]+(len(A)-ind)*b



CA=Counter(A)
CB=Counter(B)

ANS2=0

S=set(A)|set(B)

for s in S:
    ANS2+=max(CA[s],CB[s])*s

print(ANS2%mod)
print(ANS%mod)
0