CF2229G.Roadworks

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In an under-construction village, nn houses have been built in a row numbered from 11 to nn. House ii has hospitality hih_i.

The village has n−1n - 1 roads, where road ii connects houses ii and i+1i + 1 and will be built on day did_i. Initially, no roads are built.

You start at house xx and will stay in the village from day 11 to day kk, initially with a satisfaction of 00. On day ss, the following happens in order:

  • All roads ii with di=sd_i = s are built;
  • You may move to an adjacent house, if the road to it has been built, or stay at your current house;
  • Your satisfaction increases by hjh_j, where jj is the house you are currently at.

Find the maximum satisfaction you can achieve after kk days.

在一个正在建设中的村庄中,已有 nn 座房屋沿一条直线建成,编号从 11 到 nn。房屋 ii 的好客度为 hih_i。

村庄中有 n−1n - 1 条道路,其中第 ii 条道路连接房屋 ii 和 i+1i + 1,并在第 did_i 天建成。初始时,没有任何道路建成。

你从房屋 xx 出发,并将在村庄中停留第 11 天至第 kk 天,初始满意度为 00。在第 ss 天,将按以下顺序发生以下事件:

  • 所有满足 di=sd_i = s 的道路 ii 均被建成;
  • 你可以移动到一个相邻的房屋(前提是通往该房屋的道路已经建成),或者停留在当前房屋;
  • 你的满意度增加 hjh_j,其中 jj 是你当前所在的房屋。

求经过 kk 天后你能达到的最大满意度。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, kk and xx (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 1≤k≤1091 \le k \le 10^9, 1≤x≤n1 \le x \le n) — the number of houses, the number of days and the starting house, respectively.

The second line contains nn integers h1,h2,…,hnh_1, h_2, \ldots, h_n (0≤hi≤1090 \le h_i \le 10^9) — the hospitality of each house.

The third line contains n−1n - 1 integers d1,d2,…,dn−1d_1, d_2, \ldots, d_{n - 1} (1≤di≤k1 \le d_i \le k) — the day each road is built.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、kk 和 xx(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤k≤1091 \le k \le 10^9,1≤x≤n1 \le x \le n),分别表示房屋数量、天数和起始房屋编号。

第二行包含 nn 个整数 h1,h2,…,hnh_1, h_2, \ldots, h_n(0≤hi≤1090 \le h_i \le 10^9),表示每座房屋的亲和度。

第三行包含 n−1n - 1 个整数 d1,d2,…,dn−1d_1, d_2, \ldots, d_{n - 1}(1≤di≤k1 \le d_i \le k),表示每条道路建成的日期。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the maximum satisfaction you can achieve after kk days.

对于每个测试用例,输出一个整数——经过 kk 天后所能达到的最大满意度。

输入输出样例

  • 输入#1

    4
    5 10 3
    14 2 3 5 6
    10 6 2 7
    4 8 1
    0 0 0 1
    7 1 2
    2 1000000000 1
    1 1000000000
    1
    9 27 6
    17 13 5 8 14 3 4 17 20
    10 1 2 13 3 15 6 23

    输出#1

    52
    0
    1000000000000000000
    386

说明/提示

In the first test case, the following is one optimal sequence of moves:

  • You start at house x=3x = 3 with a satisfaction of 00.
  • On day 11, no roads are built yet, so you must remain at house 33. Your satisfaction becomes 33.
  • On day 22, road 33 is built. You move to house 44 and remain there on days 22, 33, 44, 55, 66 and 77. Your satisfaction becomes 3333. During this time, roads 22 and 44 are also built.
  • On day 88, you move back to house 33. Your satisfaction becomes 3636.
  • On day 99, you move to house 22. Your satisfaction becomes 3838.
  • On day 1010, road 11 is built. You move to house 11. Your satisfaction becomes 5252.

It can be shown that it is impossible to achieve a satisfaction greater than 5252.

In the second test case, you cannot reach house 44 within 88 days, so the maximum achievable satisfaction is 00.

In the third test case, you can immediately move to house 22 and remain there for 1 000 000 0001\,000\,000\,000 days.

在第一个测试用例中,以下是一种最优的移动序列:

  • 你从房屋 x=3x = 3 出发,初始满意度为 00。
  • 第 11 天,尚无道路建成,因此你必须停留在房屋 33。你的满意度变为 33。
  • 第 22 天,道路 33 建成。你移动至房屋 44,并在第 22、33、44、55、66 和 77 天均停留于该房屋。你的满意度变为 3333。在此期间,道路 22 和 44 也相继建成。
  • 第 88 天,你返回房屋 33。你的满意度变为 3636。
  • 第 99 天,你移动至房屋 22。你的满意度变为 3838。
  • 第 1010 天,道路 11 建成。你移动至房屋 11。你的满意度变为 5252。

可以证明,无法获得超过 5252 的满意度。

在第二个测试用例中,你无法在 88 天内到达房屋 44,因此可达到的最大满意度为 00。

在第三个测试用例中,你可以立即移动至房屋 22 并在那里停留 1 000 000 0001\,000\,000\,000 天。

输入解题思路,AI测评打分。不知道怎么写?

首页