| Codeforces Round 1068 (Div. 2) |
|---|
| Finished |
In the world of Plastic Memories, Isla is collecting $$$n$$$ memory fragments. The $$$i$$$-th fragment has size $$$a_i$$$, and the sizes are non-increasing, that is, $$$a_1 \ge a_2 \ge \cdots \ge a_n$$$.
During retrieval, Isla processes fragments on a range and stores their sizes into a buffer. Whenever the buffer reaches a given threshold $$$x$$$, it overflows: one capsule is recorded, and the buffer is cleared to zero.
There are $$$q$$$ independent queries, each described by a triple $$$(l,r,x)$$$. For each query, $$$x$$$ denotes Isla's memory capacity. Isla then picks up the $$$i$$$-th memory fragment one by one for each $$$l \le i \le r$$$. At any moment, if the total size of the fragments she is currently holding is at least $$$x$$$, she clears her memory completely (keeping nothing). You must determine how many times Isla clears her memory and the final sum of the size of the fragments she holds.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 150,000$$$) — the length of $$$a$$$ and the number of queries.
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of $$$a$$$. It is guaranteed that $$$a_1 \ge a_2 \ge \cdots \ge a_n$$$.
Then $$$q$$$ lines follow, each containing three integers $$$l$$$, $$$r$$$, and $$$x$$$ ($$$1 \le l \le r \le n$$$, $$$1 \le x \le 10^9$$$) — a query.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$150,000$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases does not exceed $$$150,000$$$.
For each test case, output two integers for each query — the number of times Isla clears her memory and the final sum of the size of the fragments she holds.
35 47 5 5 2 11 3 102 5 61 5 73 5 46 56 6 5 3 2 21 6 21 6 72 6 72 5 42 5 311 7938412006 792864920 746880066 729862150 704473377 550436315 381392172 326088331 316506801 301443698 1908626811 3 4172531029 11 8575924971 11 3443599211 7 4087600158 8 5447499747 10 3610901333 11 888178376
1 51 32 31 36 02 42 03 03 23 00 8088131809 06 3813921720 3260883312 3014436983 492306379
Let $$$\texttt{cnt}$$$ be how many times Isla has cleared her memory, and $$$\texttt{sum}$$$ be the total size of the fragments she is holding.
In the first test case, for the first query $$$(l, r, x) = (1, 3, 10)$$$:
Thus, we print $$$\texttt{cnt}=1$$$ and $$$\texttt{sum}=5$$$.
In the second test case, for the fifth query $$$(l, r, x) = (2, 5, 3)$$$:
| Name |
|---|


