結果

問題 No.2422 regisys?
ユーザー lam6er
提出日時 2025-04-15 23:48:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,490 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 188,536 KB
最終ジャッジ日時 2025-04-15 23:50:31
合計ジャッジ時間 12,205 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 57 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    M = int(data[idx+1])
    idx +=2
    A = list(map(int, data[idx:idx+N]))
    idx +=N
    B = list(map(int, data[idx:idx+N]))
    idx +=N
    
    G_C = []
    M_C = []
    for _ in range(M):
        T = int(data[idx])
        C = int(data[idx+1])
        idx +=2
        if T == 0:
            G_C.append(C)
        else:
            M_C.append(C)
    
    # Split into G_products and M_products
    G_products = []
    M_products = []
    for i in range(N):
        a = A[i]
        b = B[i]
        if a <= b:
            G_products.append((a, b))
        else:
            M_products.append((b, a))  # (B_i, A_i)
    
    # Sort G_C and M_C
    G_C.sort()
    M_C.sort()
    
    # Assign G_products to G_C
    sorted_g_products = sorted(G_products, key=lambda x: x[0])
    j_g = 0
    count_g = 0
    for a, _ in sorted_g_products:
        while j_g < len(G_C) and G_C[j_g] < a:
            j_g +=1
        if j_g < len(G_C):
            count_g +=1
            j_g +=1
    
    # Assign M_products to M_C
    sorted_m_products = sorted(M_products, key=lambda x: x[0])
    j_m = 0
    count_m = 0
    for b, _ in sorted_m_products:
        while j_m < len(M_C) and M_C[j_m] < b:
            j_m +=1
        if j_m < len(M_C):
            count_m +=1
            j_m +=1
    
    # Process remaining G_products (assign to M_C's remaining)
    remaining_g = sorted_g_products[count_g:]
    remaining_g_b = [b for (a, b) in remaining_g]
    remaining_g_b.sort()
    remaining_m_c = M_C[j_m:]
    remaining_m_c.sort()
    j = 0
    count_remaining_g = 0
    for b in remaining_g_b:
        while j < len(remaining_m_c) and remaining_m_c[j] < b:
            j +=1
        if j < len(remaining_m_c):
            count_remaining_g +=1
            j +=1
    
    # Process remaining M_products (assign to G_C's remaining)
    remaining_m = sorted_m_products[count_m:]
    remaining_m_a = [a for (b, a) in remaining_m]
    remaining_m_a.sort()
    remaining_g_c = G_C[j_g:]
    remaining_g_c.sort()
    j = 0
    count_remaining_m = 0
    for a in remaining_m_a:
        while j < len(remaining_g_c) and remaining_g_c[j] < a:
            j +=1
        if j < len(remaining_g_c):
            count_remaining_m +=1
            j +=1
    
    total_sold = count_g + count_m + count_remaining_g + count_remaining_m
    print(N - total_sold)

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