Chocolates and Boxes
Practice
4.2 (18 votes)
Algorithms
Approved
Math
Medium
Open
Problem
19% Success 5624 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Alice has N boxes, and each box has certain non zero number of chocolates. These boxes are numbered from 1 to N.

Alice is planning to go to wonderland. She wants to carry exactly K number of chocolates and she can carry only 2 boxes. So she wants to know the number of ways in which she can select 2 boxes such that total number of chocolates in them is K.

Input
First line of the input is the number of test cases T. It is followed by T test cases. Each test case has 3 lines. First line is the number of boxes N and the next line has N space separated integers where the ith integer is the number of chocolates in the ith box and 3rd line of each test case contains value of K.

Output
For each test case, output a single number, the number of ways in which she can select the boxes.

Constraints

1<=T(number of test cases)<=10

1<=N<=10^5

1<=Number of Chocolates in ith box<=100

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
20 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMedium
Points:30
10 votes
Tags:
Basic ProgrammingC++
Points:30
9 votes
Tags:
TreesBasic ProgrammingAlgorithms