#P11656. 「FAOI-R5」喷酒大赛

    ID: 11533 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP线段树树状数组2025洛谷原创O2优化洛谷比赛

「FAOI-R5」喷酒大赛

Background

Fire spitting is a unique and mysterious stunt in Sichuan opera. It originated in ancient Western Shu and is famous across the Chinese opera world. Face-changing performers use magic-like skills to switch masks in an instant, and when combined with the strange art of fire spitting, it shows sharp changes in characters’ emotions and the plot, creating strong inner tension. This is one of the most powerful and romantic ways Sichuan opera portrays characters. During a performance, the actor holds a tube in their mouth. Inside the tube there is pine resin powder and paper ash that has not been completely burned out. (How much it is burned matters a lot: it must be burned out, but not fully burned out.) When fire is needed, it is lit from the outside, and the actor blows outward, making sparks spray out.

The Shaoxing opera fire-spitting show at the opening ceremony of WC2025 was amazing. Even though you have not learned fire spitting, you can spray liquor.

Problem Description

There are nn performers standing on a number line. The ii-th performer stands at position ii, where ii is a positive integer. Everyone holds strong liquor in their mouth. For the ii-th performer, you may give them one coin to make them perform liquor spraying.

After you pay, performers who did not receive money leave the stage. The remaining performers, at time 00, spray liquor from their mouths toward either left or right with intensity kik_i. Formally, the liquor sprayed by performer ii has a direction attribute bib_i, and you may set bi=1b_i=1 or bi=1b_i=-1. For time t[0,ai)t\in[0,a_i), at time tt the liquor’s position is pi,t=i+tbip_{i,t}=i+t\cdot b_i. When tait\geq a_i, the liquor disappears.

Performers have special protection on their backs, but not on their fronts. If at some positive integer time tt, the liquor sprayed by performer ii still exists and there exists a remaining performer jj such that pi,t=jp_{i,t}=j, then:

  • If bi=bjb_i=b_j:
    • If ki=0k_i=0, the liquor sprayed by performer ii disappears.
    • If ki>0k_i>0, then kiki1k_i\gets k_i-1, i.e. the liquor’s intensity decreases by 11.
  • If bibjb_i\neq b_j, then performer jj gets sprayed by the liquor and angrily leaves.

You want the liquor to cover the positions [1,n][1,n] on the number line. That is, for every i[1,n]i\in[1,n], there exists at least one pair of nonnegative integers (j,t)(j,t) such that at time tt the liquor sprayed by performer jj still exists and pj,t=ip_{j,t}=i. Find the minimum number of coins needed, under the conditions that this goal is achieved and no performer leaves angrily.

Input Format

The first line contains a positive integer nn, denoting the number of performers.

The second line contains nn positive integers. The ii-th number is aia_i, denoting the distance the ii-th performer’s liquor can spray.

The third line contains nn positive integers. The ii-th number is kik_i, denoting the intensity of the ii-th performer’s liquor.

Output Format

Output one positive integer in one line, denoting the minimum cost to cover [1,n][1,n].

10
1 1 4 5 1 4 1 2 1 2
1 1 2 0 3 1 2 0 2 1
3
10
1 1 9 2 4 9 2 2 1 1
1 0 3 2 3 0 3 8 2 1
3
24
1 4 5 2 3 1 4 2 5 3 1 1 1 3 2 1 1 1 1 2 2 1 1 3 
1 1 4 0 3 0 0 4 0 5 3 2 0 3 2 1 0 3 2 0 0 2 1 1
10

Hint

Sample Explanation

  • Sample #1: Give coins to performers 3,4,103,4,10, and set b3=1,b4=1,b10=1b_3=-1,b_4=1,b_{10}=-1.
  • Sample #2: Give coins to performers 1,2,31,2,3, and set b1=1,b2=1,b3=1b_1=-1,b_2=-1,b_{3}=1.

Constraints and Notes

This problem uses bundled testdata.

  • Subtask 1 (20 pts): n14n\leq 14.
  • Subtask 2 (10 pts): n50n\leq 50, ki=0k_i=0.
  • Subtask 3 (15 pts): n50n\leq 50.
  • Subtask 4 (20 pts): n103n\leq 10^3.
  • Subtask 5 (15 pts): n105n\leq 10^5.
  • Subtask 6 (20 pts): no special restrictions.

For all testdata, 1n,ai5×1051\leq n,a_i\leq 5\times 10^5, 0ki5×1050\le k_i\le5\times10^5.

Translated by ChatGPT 5