#P15848. [NOISG 2026 Finals] Famished Cats

    ID: 18384 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心优先队列2026NOISG(新加坡)

[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 nn cat houses to the east of the food bank, numbered from 1 to nn. It is guaranteed that nn is even. The first house is d[1]d[1] kilometres east of the food bank. For i2i \geq 2, the ii-th house is d[i]d[i] kilometres east of the (i1)(i - 1)-th house.

Ket will drive a delivery truck to deliver food to the houses. The truck starts from the food bank and initially has xx units of fuel. 1 unit of fuel allows Ket to drive his truck 1 kilometre along the road.

The ii-th house has f[i]f[i] 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 ii-th and (ni+1)(n - i + 1)-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 DD he can reach, using any number of swaps. Also, help Ket find the minimum number of swaps SS required to reach house DD.

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 nn and xx.

The second line of input contains nn space-separated integers d[1],d[2],,d[n]d[1], d[2], \dots, d[n].

The third line of input contains nn space-separated integers f[1],f[2],,f[n]f[1], f[2], \dots, f[n].

Output Format

Your program must print to standard output.

Output two space-separated integers on a single line. The first integer should be DD, the index of the furthest house Ket can reach, followed by SS, the minimum number of swaps required to reach house DD.

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 n=6n = 6 houses to its east. Ket’s truck starts with x=1x = 1 unit of fuel and moves to house 11. He then refuels at house 11 and drives to house 22. At this point, it is optimal for Ket to use his magic wand to swap the fuel amounts in houses 22 and 55, allowing him to refill 33 units of fuel and reach house 33. Subsequently, he can refill 11 unit of fuel before travelling to the next two houses, refilling 44 and 11 units (due to the earlier swap) of fuel in houses 44 and 55 respectively.

He will then have 44 units of fuel left, leaving him unable to travel to house 66 as it requires 66 units of fuel. Since Ket runs out of fuel before reaching house 66, he can only travel to house 55. Furthermore, he had to make one swap with his magic wand. Therefore, D=5D = 5 and S=1S = 1.

Subtasks

For all test cases, the input will satisfy the following bounds:

  • 2n5000002 \leq n \leq 500\,000
  • nn is even.
  • 1d[i]1091 \leq d[i] \leq 10^9 for all 1in1 \leq i \leq n
  • 1f[i]1091 \leq f[i] \leq 10^9 for all 1in1 \leq i \leq n
  • d[1]x109d[1] \leq x \leq 10^9

Your program will be tested on input instances that satisfy the following restrictions:

Subtask Score Additional constraints
0 Sample test cases
1 7 f[i]f[ni+1]=k\vert f[i] - f[n - i + 1] \vert = k for some constant kk, for all 1in1 \leq i \leq n
2 12 n40n \leq 40
3 14 ff is non-decreasing (f[i]f[i+1]f[i] \leq f[i + 1] for all 1in11 \leq i \leq n - 1)
4 19 Dn2D \leq \frac{n}{2}
5 21 n5000n \leq 5000
6 27 No additional constraints

Note: The absolute value of a number xx, denoted x\vert x \vert, is the non-negative number equal to the distance between 00 and xx on a number line. For example, 5=5\vert 5 \vert = 5 and 5=5\vert -5 \vert = 5.