結果

問題 No.3023 Utility is Max?
ユーザー ArcAki
提出日時 2025-01-12 03:23:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 81,224 KB
最終ジャッジ日時 2025-01-12 03:23:46
合計ジャッジ時間 9,046 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

# GPT-o1生成コード

def solve():
    import sys
    input = sys.stdin.readline
    
    Q = int(input())
    ans = []
    
    for _ in range(Q):
        I = int(input())
        
        A1, B1, X1, Y1 = map(int, input().split())
        A2, B2, X2, Y2 = map(int, input().split())
        
        cost1 = A1*X1 + B1*Y1
        cost2 = A2*X2 + B2*Y2
        
        # 1) 予算チェック
        if cost1 > I or cost2 > I:
            ans.append("No")
            continue
        
        # 予算をピッタリ使っていない(余りがある)なら絶対最適になりえない
        if cost1 < I or cost2 < I:
            ans.append("No")
            continue
        
        # 2) 両店指定量が同じか?
        if (X1 == X2) and (Y1 == Y2):
            # 同じベクトルを両店で買っている → クロスフィージビリティの矛盾は起こらない
            ans.append("Yes")
            continue
        
        # 3) (X2,Y2)が店1制約下でも買える?
        cross1 = (A1*X2 + B1*Y2 <= I)
        #    (X1,Y1)が店2制約下でも買える?
        cross2 = (A2*X1 + B2*Y1 <= I)
        
        # 両方向同時に feasible なら矛盾→No
        if cross1 and cross2:
            ans.append("No")
        else:
            ans.append("Yes")
    
    print("\n".join(ans))


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