Submit | All submissions | Best solutions | Back to list |
OPCPIZZA - Pizzamania |
Singham and his friends are fond of pizza. But this time they short of money. So they decided to help each other. They all decided to bring pizza in pairs. Our task is to find the total number of pairs possible which can buy pizza, given the cost of pizza. As pizza boy don't have any cash for change, if the pair adds up to more money than required, than also they are unable to buy the pizza. Each friend is guaranteed to have distinct amount of money. As it is Singham's world, money can also be negative ;).
Input
The first line consist of t (1 <= t <= 100) test cases. In the following 2*t lines, for each test case first there is n and m, where n (1 <= n <= 100000) is number of Singham's friend and m is the price of pizza. The next line consist of n integers, separated by space, which is the money each friend have.
The value of m and money is within the limits of int in C, C++.
Output
A single integer representing the number of pairs which can eat pizza.
Example
Input: 2 4 12 9 -3 4 3 5 -9 -7 3 -2 8 7 Output: 1 1
Added by: | ! include(L.ppt) |
Date: | 2012-08-31 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | MNNIT OPC 31-08-2012 |
hide comments
|
||||||||
2024-03-13 10:35:21
0.48 with binary search |
||||||||
2023-05-22 07:29:03
LoL this problem is for C++ solution I got AC with C++ but TLE with Python |
||||||||
2021-11-28 01:23:30 vas14
Firstly, there are identical numbers in the input (tested with assert). Secondly, for 6 7 1 1 1 1 6 6 it expects 3 as the answer. Last edit: 2021-11-28 01:23:44 |
||||||||
2021-03-18 14:42:47
Done it in O( nlogn + n) using 2-pointers!! :) |
||||||||
2020-10-28 08:52:46
i made 0(n) time complexity by using set still its TLE?? |
||||||||
2020-01-01 18:11:36
they all have 'distinct' amount of money;) |
||||||||
2019-10-08 06:18:16
I keep getting TLE using Java. I'm using binary search but it's still TLE. My algorithm is same as many people who got AC here. I already use BufferedReader to read input. what should I fix? |
||||||||
2018-10-23 21:52:09
can anyone please explain: how is this a question of binary search? i solved it using two pointer approach. Last edit: 2018-10-23 21:52:58 |
||||||||
2018-09-08 04:17:49
Why the solutions for 1 8 10 9 9 1 1 1 1 1 1 and 1 8 10 1 1 9 9 9 9 9 9 are different ? Edit: Sorry. Each friend is guaranteed to have distinct amount of money Last edit: 2018-09-08 04:39:15 |
||||||||
2018-06-21 20:09:20
This problem has large inputs. Either use scanf or use ios_base statement with cin/cout |