#P15800. [GESP202603 六级] 选数

[GESP202603 六级] 选数

Background

Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1210.

Problem Description

Given two arrays a=[a1,…,an]a=[a_1,\dots,a_n] and b=[b1,…,bn]b=[b_1,\dots,b_n], each containing nn integers. You need to choose some indices p1<⋯<pkp_1< \cdots< p_k (1≤k≤n1\leq k\leq n) such that the following conditions are satisfied:

  • 1≤pi≤n1\leq p_i\leq n (1≤i≤k1\leq i\leq k).
  • pi+1≥pi+bpip_{i+1}\geq p_i+b_{p_i} (1≤i<k1\leq i< k).

Under these conditions, you need to maximize ∑i=1kapi\sum_{i=1}^k a_{p_i}, i.e., maximize the sum of the values in array aa at the chosen indices.

Input Format

The first line contains a positive integer nn, indicating the array length.

The second line contains nn positive integers a1,a2,…,ana_1,a_2,\dots,a_n, representing array aa.

The third line contains nn positive integers b1,b2,…,bnb_1,b_2,\dots,b_n, representing array bb.

Output Format

One line containing an integer, representing the maximum possible sum of the values in array aa at the chosen indices, under the index constraints.

4
1 2 3 4
3 3 1 1
7
6
1 1 4 5 1 4
1 2 3 2 1 0
11

Hint

For 40%40\% of the testdata, it is guaranteed that 2≤n≤1032\leq n\leq 10^3.

For all testdata, it is guaranteed that 2≤n≤1052\leq n\leq 10^5, 0≤ai≤1090\leq a_i\leq 10^9, and 0≤bi≤n0\leq b_i\leq n.

Translated by ChatGPT 5