0% found this document useful (0 votes)
2 views2 pages

Problem - B - Codeforces

Uploaded by

divyaaak.2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Problem - B - Codeforces

Uploaded by

divyaaak.2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

6/26/25, 11:16 PM Problem - B - Codeforces

|
divya8080 | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

00:00:56

Codeforces Round 980 (Div. 1)


Finished
B. Skipping
time limit per test: 2 seconds Practice
memory limit per test: 256 megabytes

It is already the year 3024 , ideas for problems have long run out, and the olympiad now takes
place in a modified individual format. The olympiad consists of n problems, numbered from 1 to → Virtual participation 
n. The i -th problem has its own score ai and a certain parameter bi (1 ≤ bi ≤ n ).
Virtual contest is a way to take part in past
Initially, the testing system gives the participant the first problem. When the participant is given contest, as close as possible to participation
on time. It is supported only ICPC mode for
the i -th problem, they have two options: virtual contests. If you've seen these
problems, a virtual contest is not for you -
solve these problems in the archive. If you
They can submit the problem and receive ai points; just want to solve some problem from a
They can skip the problem, in which case they will never be able to submit it. contest, a virtual contest is not for you -
solve this problem in the archive. Never use
someone else's code, read the tutorials or
Then, the testing system selects the next problem for the participant from problems with indices communicate with other person during a
j , such that: virtual contest.

Start virtual contest


If he submitted the i -th problem, it looks at problems with indices j < i ;
If he skipped the i -th problem, it looks at problems with indices j ≤ bi .

Among these problems, it selects the problem with the maximum index that it has not → Clone Contest to Mashup 
previously given to the participant (he has neither submitted nor skipped it before). If there is no
You can clone this contest to a mashup.
such problem, then the competition for the participant ends, and their result is equal to the sum of
points for all submitted problems. In particular, if the participant submits the first problem, then the Clone Contest
competition for them ends. Note that the participant receives each problem at most once.

Prokhor has prepared thoroughly for the olympiad, and now he can submit any problem. Help him
→ Submit?
determine the maximum number of points he can achieve.

Input Language: Java 8 32bit

Each test consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10
5
) Choose
Choose File No file chosen
— the number of test cases. The description of the test cases follows. file:

Submit
The first line of each test case contains a single integer n (1
5
≤ n ≤ 4 ⋅ 10 ) — the number of
problems in the olympiad.

→ Contest materials
9
The second line of each test case contains n integers a1 , a2 , … , an (1 ≤ ai ≤ 10 ) — the
scores of the problems.
Announcement
The third line of each test case contains n integers b1 , b2 , … , bn (1 ≤ bi ≤ n ) — the
parameters of the problems. Tutorial (en)

It is guaranteed that the sum of n over all test cases does not exceed 4 ⋅ 105 .

Output
For each test case, output a single integer — the maximum number of points that Prokhor can
achieve.

Example
input Copy

4
2
15 16
2 1
5
10 10 100 100 1000
3 4 1 1 1
3
100 49 50
3 2 2
4
100 200 300 1000

[Link] 1/2
6/26/25, 11:16 PM Problem - B - Codeforces
2 3 4 1

output Copy

16
200
100
1000
Note
In the first test case, Prokhor can skip the first problem; then he will receive the problem with
index b1 = 2 . Prokhor can submit it and receive a2 = 16 points. After that, the competition will
end because Prokhor has already received all problems. Note that if Prokhor submits the first
problem, he will receive a1 = 15 points, but the competition will end immediately.

In the second test case, Prokhor can skip the first problem; then he will receive the problem with
index b1 = 3 . Prokhor can submit it and receive a3 = 100 points. After that, Prokhor will receive
the second problem, which he can skip to receive the problem with index b2 = 4 . Prokhor can
submit the fourth problem and receive another a4 = 100 points. After that, the competition ends
because Prokhor has already received all problems with indices not exceeding 4. Thus, Prokhor
will receive a total of 200 points.

In the third test case, Prokhor can submit the first problem and receive 100 points, after which the
competition will end immediately.

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jun/26/2025 23:14:37UTC+5.5 (l3).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions

Supported by

[Link] 2/2

You might also like