#P9029. [COCI 2022/2023 #1] Čokolade
[COCI 2022/2023 #1] Čokolade
Background
Lana and Fran are visiting a chocolate factory, and now they want to buy some chocolates.
Problem Description
There are different chocolates in the factory, and the price of the -th chocolate is . Lana and Fran want to buy chocolates.
Fran has a payment plan:
- If the chocolate price is less than , the full cost of this chocolate will be paid by Lana.
- Otherwise, Lana will pay , and Fran will pay the remaining part, i.e. .
Lana is not happy with Fran's plan and wants to get back at Fran. Let be the amount Lana needs to pay, and be the amount Fran needs to pay. Lana will choose a buying plan that minimizes the value of .
Since Fran is still hesitating and does not know how many chocolates to buy, Lana wants to know, for the given different plans and , the minimum value of for each plan.
Input Format
The first line contains two integers and , representing the number of chocolates and the number of queries.
The second line contains integers , in order, representing the price of each chocolate.
The next lines each contain two integers and , representing Fran's payment threshold and the total number of chocolates to buy.
Output Format
Output lines, each containing one integer representing the answer to Lana's query.
5 2
1 9 22 10 19
18 4
5 2
34
-21
7 4
1 5 4 3 7 11 9
5 4
5 7
7 3
4 5
4
16
7
1
3 3
5 6 7
10 1
5 3
3 3
5
12
0
Hint
| Subtask | Score | Special Properties |
|---|---|---|
| All queries have the same | ||
| No special properties |
For of the data, .
The full score of this problem is points.
Translated by ChatGPT 5