| TeamsCode Summer 2026 Contest |
|---|
| Закончено |
You are thirsty, and the only thing you can drink is tea. Unfortunately, you hate tea because it is too bitter!
You initially have $$$t$$$ mL of tea and $$$w$$$ mL of fresh water. Because you are thirsty, you must drink exactly $$$s$$$ ($$$1 \le s \le t+w$$$) mL of tea. (You cannot drink fresh water.) You are also given an array $$$B_i$$$ ($$$1 \le i \le t+w$$$) denoting the bitterness you feel when you drink tea.
At any point in time, you can do one of two things:
Find the minimum total bitterness you can have while drinking enough tea to not be thirsty.
Each test contains multiple test cases. The first line contains the number of test cases $$$n$$$ $$$(1 \leq n \leq 1000)$$$. The description of the test cases follows.
The first line of each test case contains three integers $$$t$$$, $$$w$$$, and $$$s$$$ $$$(1 \leq t + w \leq 2 \cdot 10^5, 1 \leq s \leq t+w)$$$.
The second line of input contains $$$t+w$$$ space-separated integers $$$B_1, B_2, ..., B_{t+w}$$$ $$$(1 \leq B_i \leq 10^3)$$$.
The sum of $$$t+w$$$ across all test cases is guaranteed to not exceed $$$2 \cdot 10^5$$$.
—
Tests in subtasks are numbered from $$$1$$$ — $$$20$$$ with samples skipped. Each subtask is worth $$$5$$$ points.
Tests $$$2$$$ — $$$3$$$ satisfy $$$t + w \leq 10$$$ for each test case.
Tests $$$4$$$ — $$$5$$$ satisfy $$$t + w \leq 200$$$ for each test case.
Tests $$$6$$$ — $$$8$$$ satisfy $$$t + w \leq 2 \cdot 10^3$$$ for each test case.
Tests $$$9$$$ — $$$20$$$ satisfy no additional constraints.
For each test case, output the minimum total bitterness you can have while drinking enough tea to not be thirsty.
65 0 51 2 3 4 55 5 31 2 3 4 5 6 7 8 9 105 5 310 9 8 7 6 5 4 3 2 11 5 61 100 100 100 100 1005 3 3100 100 100 100 100 100 100 15 3 3100 100 100 1 100 100 100 100
151266201102
In the first test case, you have no fresh water, so you must drink all of the tea and have a total bitterness of $$$5 + 4 + 3 + 2 + 1 = 15$$$.
In the second test case, it is optimal to not add any fresh water and only drink tea, for a total bitterness of $$$B_5 + B_4 + B_3 = 5 + 4 + 3 = 12$$$.
In the third test case, it is optimal to add all 5 mL of fresh water before drinking the tea, for a total bitterness of $$$B_{10} + B_9 + B_8 = 1 + 2 + 3 = 6$$$.
An optimal sequence of moves for the sixth test case is as follows:
| Название |
|---|


