| SanSi Cup 2026 Qualification round |
|---|
| Finished |
Felipe is a bandit: he has two special lady friends and, every time he goes on a trip, he likes to bring gifts to both. But he has a favorite, and he always gives her the best gifts.
In the store there are $$$n$$$ different gifts, and the $$$i$$$-th costs $$$a_i$$$ Bs. Each gift can be bought only once. On each trip, Felipe buys like this:
Felipe makes $$$q$$$ trips. Each trip is independent: the store always starts with the $$$n$$$ gifts. For each trip, how many gifts does each of them receive?
The first line contains two integers $$$n$$$ and $$$q$$$: the number of gifts and the number of trips.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$: the prices of the gifts.
Each of the following $$$q$$$ lines contains two integers $$$X$$$ and $$$Y$$$: what Felipe is willing to spend on the favorite and on the second one on that trip.
Constraints
For each trip, print on one line two integers separated by a space: the number of gifts the favorite receives and the number the second one receives.
5 3 5 1 4 2 3 10 2 5 100 9 3
2 1 1 4 2 2
3 2 7 7 7 20 7 7 14
2 1 1 2
Example 1. On the first trip, Felipe buys the gifts of $$$5$$$ and $$$4$$$ Bs for the favorite and has $$$1$$$ Bs left, which is not enough for the one of $$$3$$$. For the second one, the gifts of $$$1$$$, $$$2$$$ and $$$3$$$ are left: he buys the one of $$$1$$$, and the remaining $$$1$$$ Bs is not enough for the one of $$$2$$$. On the second trip, the favorite receives the one of $$$5$$$ and he spends everything, and for the second one he buys the four that are left for $$$10$$$ Bs. On the third, the favorite receives the ones of $$$5$$$ and $$$4$$$, which add up to exactly $$$9$$$, and the second one the ones of $$$1$$$ and $$$2$$$, which add up to exactly $$$3$$$.
Example 2. On the first trip, the favorite receives two gifts of $$$7$$$ Bs, because a third one would make $$$21 \gt 20$$$, and the second one receives the one that is left.
| Name |
|---|


