問題一覧 > 通常問題

No.1715 Dinner 2

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 75
作問者 : nok0 / テスター : zkou Kite_kuma ygussany
お気に入りにしたユーザー ProblemId : 7113 / 自分の提出
問題文最終更新日: 2021-10-17 19:35:40
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 319 (順位表) の他の問題:

Problem Statement

Kite_kuma, who has started living alone, has decided to cook his own dinner for the next $D$ days.

Initially, Kite_kuma's energy level is $0$. Each day, he chooses one of $N$ types of dishes, cooks it, and then eats it. Cooking the $i$-th dish decreases his energy level by $P_i$, and then eating the dish increases his energy level by $Q_i$. However, since he would get tired of eating the same type of dish on consecutive days, such a choice of dishes is forbidden.

Kite_kuma always wants to stay energetic, so he acts so as to maximize the minimum value of his energy level during the $D$ days.
Under the above conditions, find the minimum value of Kite_kuma's energy level during the $D$ days. Assume that Kite_kuma's energy level changes only through cooking and eating his dinners.

Constraints

  • All inputs are integers.
  • $2 \le N,D \le 10^3 $
  • $1 \le P_i,Q_i \le 10^5$

Input

$N$ $D$
$P_1$ $Q_1$
$P_2$ $Q_2$
$\vdots$
$P_N$ $Q_N$

Output

Print the minimum value of Kite_kuma's energy level during the $D$ days under the given conditions.

Sample

Sample 1
Input
2 2
3 3
1 2
Output
-2

By making dish $2$ on day $1$ and dish $1$ on day $2$, Kite_kuma's energy level changes as

$0 \to -1 \to 1 \to -2\to 1$

In this case, the minimum energy level is $-2$.

The minimum energy level cannot be made greater than $-2$, so the answer is $-2$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。