#P15848. [NOISG 2026 Finals] Famished Cats
[NOISG 2026 Finals] Famished Cats
Problem Description
After successfully preventing the extinction of cats during the annual National Cat Day (NCD) celebration, Ket the cat has now received hunger complaints from the kingdom of cannibalistic cats. Hence, Ket has been tasked with delivering food to prevent them from resorting to cannibalism again.
This cat kingdom can be modelled as a very long road that runs from west to east. There is a food bank at the west end of the road. There are cat houses to the east of the food bank, numbered from 1 to . It is guaranteed that is even. The first house is kilometres east of the food bank. For , the -th house is kilometres east of the -th house.
Ket will drive a delivery truck to deliver food to the houses. The truck starts from the food bank and initially has units of fuel. 1 unit of fuel allows Ket to drive his truck 1 kilometre along the road.
The -th house has units of fuel for the truck to use. The truck has infinite fuel storage and stops only when it runs out of fuel. The truck does not need to return to the food bank after leaving.
:::align{center}
:::
In addition, Ket has a magic wand. In one wave of his wand, he can swap the amount of fuel stored in the -th and -th cats’ houses. This swap can only take place if the fuels in both houses have not been used yet. Help Ket find the index of the farthest house he can reach, using any number of swaps. Also, help Ket find the minimum number of swaps required to reach house .
You may refer to Sample Test Case 1 for a more detailed explanation.
Input Format
Your program must read from standard input.
The first line of input contains two space-separated integers and .
The second line of input contains space-separated integers .
The third line of input contains space-separated integers .
Output Format
Your program must print to standard output.
Output two space-separated integers on a single line. The first integer should be , the index of the furthest house Ket can reach, followed by , the minimum number of swaps required to reach house .
6 1
1 1 3 1 1 6
1 1 1 4 3 2
5 1
6 5
3 8 3 1 4 1
2 7 1 6 2 7
6 1
6 2
2 24 25 40 5 11
4 12 14 16 20 30
3 2
6 10
3 6 3 7 8 6
4 3 1 7 1 6
5 1
Hint
Sample Test Case 1 Explanation
:::align{center}
:::
There is a food bank with houses to its east. Ket’s truck starts with unit of fuel and moves to house . He then refuels at house and drives to house . At this point, it is optimal for Ket to use his magic wand to swap the fuel amounts in houses and , allowing him to refill units of fuel and reach house . Subsequently, he can refill unit of fuel before travelling to the next two houses, refilling and units (due to the earlier swap) of fuel in houses and respectively.
He will then have units of fuel left, leaving him unable to travel to house as it requires units of fuel. Since Ket runs out of fuel before reaching house , he can only travel to house . Furthermore, he had to make one swap with his magic wand. Therefore, and .
Subtasks
For all test cases, the input will satisfy the following bounds:
- is even.
- for all
- for all
Your program will be tested on input instances that satisfy the following restrictions:
| Subtask | Score | Additional constraints |
|---|---|---|
| 0 | Sample test cases | |
| 1 | 7 | for some constant , for all |
| 2 | 12 | |
| 3 | 14 | is non-decreasing ( for all ) |
| 4 | 19 | |
| 5 | 21 | |
| 6 | 27 | No additional constraints |
Note: The absolute value of a number , denoted , is the non-negative number equal to the distance between and on a number line. For example, and .