結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー lam6er
提出日時 2025-03-31 17:52:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,448 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 77,764 KB
最終ジャッジ日時 2025-03-31 17:53:53
合計ジャッジ時間 2,664 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    N, H, X = map(int, input().split())
    G = int(input())
    g = list(map(int, input().split()))
    B = int(input())
    b = list(map(int, input().split()))
    
    g.sort()
    b.sort()
    
    intervals = set()
    
    for p in g + b:
        min_a = max(1, p - (X - 2))
        max_a = min(p, N - X + 1)
        if min_a > max_a:
            continue
        for a in range(min_a, max_a + 1):
            interval_start = a
            interval_end = a + X - 2
            intervals.add((interval_start, interval_end))
    
    valid_intervals = []
    for start, end in intervals:
        g_start = bisect.bisect_left(g, start)
        g_end = bisect.bisect_right(g, end)
        g_count = g_end - g_start
        
        b_start = bisect.bisect_left(b, start)
        b_end = bisect.bisect_right(b, end)
        b_count = b_end - b_start
        
        gain = b_count - g_count
        if gain > 0:
            valid_intervals.append((start, end, gain))
    
    valid_intervals.sort(key=lambda x: (-x[2], x[1]))
    
    selected = []
    current_end = -1
    for interval in valid_intervals:
        start, end, gain = interval
        if start > current_end:
            selected.append(gain)
            current_end = end
            if len(selected) == H:
                break
    
    sum_gain = sum(selected)
    initial = G - B
    print(initial + sum_gain)

if __name__ == "__main__":
    main()
0