問題一覧 > 通常問題

No.2161 Black Market

レベル : / AI推定難易度 : 1750 / 実行時間制限 : 1ケース 7.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 42
作問者 : 👑 AngrySadEight / テスター : tko919
お気に入りにしたユーザー ProblemId : 8864 / 自分の提出
問題文最終更新日: 2022-12-09 02:59:33
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
Advent Calendar Contest 2022 (順位表) の他の問題:

Problem Statement

There are $N$ cards. Each card has two attributes, cost and value; the cost of the $i$-th card is $A_i$ and its value is $B_i$.

You will choose at most $K$ of these $N$ cards, take them with you, and head to the black market. However, the sum of the costs of the cards you take must be at most $L$. The trade succeeds if and only if the sum of the values of the cards you take is at least $P$.

Find the number of ways to choose cards such that the trade can be made successful.

Here, two ways of choosing are considered different if there exists a card that is chosen in one of them and not chosen in the other.

Constraints

  • All input values are integers.
  • $1 \leq N \leq 34$
  • $1 \leq K \leq N$
  • $1 \leq L,P \leq 10^9$
  • $1 \leq A_i,B_i \leq 10^9$

Input

The input is given from standard input in the following format.

$N$ $K$ $L$ $P$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_N$ $B_N$

Output

Output the answer.

Sample

Sample 1
Input
4 2 4 5
1 2
2 3
3 4
4 5
Output
3

If you choose the $1$-st card and the $2$-nd card, the total cost is $3$ and the total value is $5$, so the trade succeeds. The trade also succeeds if you choose the $1$-st card and the $3$-rd card, or if you choose only the $4$-th card.

On the other hand, note that if you choose the $2$-nd card and the $3$-rd card, the total value is $7$, but the total cost is $5$, which violates the condition that the total cost must be at most $4$.

Sample 2
Input
5 5 10 10
2 2
2 2
2 2
2 2
2 2
Output
1

The trade does not succeed unless you choose all the cards.

Sample 3
Input
18 5 100 2022
35 890
35 1016
6 9
6 1341
6 398
6 500
6 495
7 406
11 310
11 514
128 321
13 210
13 35
14 99
14 884
18 340
18 1127
18 109
Output
5646

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