結果

問題 No.2422 regisys?
ユーザー lam6er
提出日時 2025-03-31 17:34:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 190,560 KB
最終ジャッジ日時 2025-03-31 17:35:41
合計ジャッジ時間 15,025 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 50 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

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
    
    t0 = []
    t1 = []
    
    for _ in range(M):
        T = int(data[idx])
        C = int(data[idx+1])
        idx +=2
        if T == 0:
            t0.append(C)
        else:
            t1.append(C)
    
    # Sort the buyers' lists
    t0.sort()
    t1.sort()
    
    # Prepare products with their min_p, preferred type, a, b
    products = []
    for i in range(N):
        a = A[i]
        b = B[i]
        min_p = min(a, b)
        preferred = 0 if a <= b else 1
        products.append( (min_p, preferred, a, b) )
    
    # Sort products by min_p
    products.sort(key=lambda x: x[0])
    
    ptr0 = 0
    ptr1 = 0
    count = 0
    
    for p in products:
        min_p, preferred, a, b = p
        
        if preferred == 0:
            # Try T0 first
            idx0 = bisect.bisect_left(t0, a, ptr0)
            if idx0 < len(t0):
                count +=1
                ptr0 = idx0 +1
            else:
                # Try T1's B price
                idx1 = bisect.bisect_left(t1, b, ptr1)
                if idx1 < len(t1):
                    count +=1
                    ptr1 = idx1 +1
        else:
            # Try T1 first
            idx1 = bisect.bisect_left(t1, b, ptr1)
            if idx1 < len(t1):
                count +=1
                ptr1 = idx1 +1
            else:
                # Try T0's A price
                idx0 = bisect.bisect_left(t0, a, ptr0)
                if idx0 < len(t0):
                    count +=1
                    ptr0 = idx0 +1
    
    print(N - count)

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