#K46317. Taco Purchase Problem

    ID: 27950 Type: Default 1000ms 256MiB

Taco Purchase Problem

Taco Purchase Problem

Ali is looking to buy exactly two different items from a store, but he has a limited budget. Given a list of item costs, your task is to determine if there exists a pair of two distinct items whose combined cost does not exceed his budget B. More formally, given a list of costs \(a_1,a_2,\ldots,a_N\), check if there exist indices \(i\) and \(j\) with \(i<j\) such that

\(a_i + a_j \leq B\)

If such a pair exists, output 1; otherwise, output 0.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  • The first line contains an integer \(T\), the number of test cases.
  • Each test case consists of two lines:
    • The first line contains two space-separated integers \(N\) and \(B\), where \(N\) is the number of items and \(B\) is the budget.
    • The second line contains \(N\) space-separated integers representing the cost of each item.

outputFormat

For each test case, output a single line on standard output (stdout) containing 1 if there exists a pair \((i, j)\) with \(a_i + a_j \leq B\) (\(i<j\)), and 0 otherwise.

## sample
3
4 7
1 2 3 4
5 10
9 2 8 1 6
3 5
5 5 5
1

1 0

</p>