結果
| 問題 | 
                            No.200 カードファイト!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-03-26 15:52:46 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,092 bytes | 
| コンパイル時間 | 181 ms | 
| コンパイル使用メモリ | 82,676 KB | 
| 実行使用メモリ | 60,104 KB | 
| 最終ジャッジ日時 | 2025-03-26 15:53:12 | 
| 合計ジャッジ時間 | 2,297 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 WA * 21 | 
ソースコード
n = int(input())
a = int(input())
b = list(map(int, input().split()))
c = int(input())
d = list(map(int, input().split()))
# Sort A's cards in descending order
b_sorted = sorted(b, reverse=True)
# Sort C's cards in ascending order
d_sorted = sorted(d)
# Calculate initial wins in the first 'a' matches
initial_wins = 0
used = [False] * len(d_sorted)
for card in b_sorted:
    for i in range(len(d_sorted)):
        if not used[i] and d_sorted[i] < card:
            initial_wins += 1
            used[i] = True
            break
# Collect remaining cards for C
d_remaining = [d_sorted[i] for i in range(len(d_sorted)) if not used[i]]
# Calculate wins in remaining matches
if a >= n:
    print(initial_wins)
else:
    rem = n - a
    if not d_remaining:
        print(initial_wins)
        exit()
    b_max = b_sorted[0]
    k = sum(1 for x in d_remaining if x < b_max)
    m = len(d_remaining)
    cycles = rem // m
    remainder = rem % m
    rem_wins = cycles * k
    rem_wins += sum(1 for x in d_remaining[:remainder] if x < b_max)
    total = initial_wins + rem_wins
    print(total)
            
            
            
        
            
lam6er