結果

問題 No.3409 How Many Gift Boxes?
コンテスト
ユーザー tassei903
提出日時 2025-12-16 01:19:26
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,145 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 128 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 124,348 KB
最終ジャッジ日時 2025-12-17 21:18:47
合計ジャッジ時間 6,506 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################


"""
 1 2 3
00
11
11
2.2
3..3

 11114
11111.
2....2
2....2
4....4

"""

mod = 10 ** 9 + 7

from collections import defaultdict
def solve1(h, w, a, b):
    d = defaultdict(int)
    for i in range(h):
        d[a[i]] += 1 << 32
    
    for j in range(w):
        d[b[j]] += 1
    
    ans = 0
    for i in d:
        x, y = divmod(d[i], 1 << 32)
        # print(i, x, y)
        ans += i * max(x, y)
    return ans % mod

def solve2(h, w, a, b):
    i = 0
    j = 0
    ans = 0
    while i < h and j < w:
        if a[i] < b[j]:
            ans += (w - j) * a[i]
            i += 1
        else:
            ans += (h - i) * b[j]
            j += 1
    return ans % mod

h, w = na()
a = sorted(na())
b = sorted(na())

# print(a)
# print(b)
print(solve1(h, w, a, b))
print(solve2(h, w, a, b))
0