結果
| 問題 | No.818 Dinner time | 
| コンテスト | |
| ユーザー | 👑  SPD_9X2 | 
| 提出日時 | 2025-10-26 16:58:46 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 852 bytes | 
| コンパイル時間 | 438 ms | 
| コンパイル使用メモリ | 82,320 KB | 
| 実行使用メモリ | 77,172 KB | 
| 最終ジャッジ日時 | 2025-10-26 16:58:51 | 
| 合計ジャッジ時間 | 4,196 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 27 WA * 2 | 
ソースコード
"""
https://yukicoder.me/problems/no/818
2~K-1日目までは同じだろう
1 2 Last
A A A    0<B<A
A A B    0<A<B
B - -    A<0 のものは使用するならこれ?
- - B    存在する? -> メリット無さそう
- - -
"""
N,M = map(int,input().split())
now = [0,0]
ans = 0
ed = 1
fi = 0 if M==1 else 1
mid = M - ed - fi
for i in range(N):
    A,B = map(int,input().split())
    n2 = [float("-inf"),float("-inf")]
    if 0 <= A <= B:
        n2[0] = max(n2[0], now[0] + fi * A + mid * A + ed * B)
        n2[1] = max(n2[1], max(now) + B)
    elif B <= A and 0 <= A:
        n2[0] = max(n2[0], now[0] + A * M)
        n2[1] = max(n2[1], max(now) + A)
    else:
        n2[0] = max(n2[0], now[0] + max(A*M,B))
        n2[1] = max(n2[1], max(now) + max(A,B))
    # print (n2)
    
    now = n2
    ans = max(ans, max(now))
print (ans)
            
            
            
        