The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
There are N players named as 1,2,...,N. Each player has a skill value(call it S) which is a positive integer.
Higher the skill value better the player. All players are standing in a circle in the order 1,2,3...N.
Each player have a dispute with some players standing next to him. Players standing next to 1 are {2,3,...,N}
and players standing next to N are {1,2,3,...,N-1}
You are given N the numbers of players, the skill value S of every player and D the player's dispute number.
If the dispute number of a player is D then he has dispute with D players standing right next to him.
You have to form a un-disputed(such that no player in the team has dispute with any other player in the team) team with maximum skill. The skill of a team is the sum of skill values of all the players in the team.
Â
Â
First line will contain the number of test cases T.
For each test case the first line will contain N, numbers of players.
Second line of the test case will contain skill values(S) of all N players separated by space.
Third line of the test case will contain the dispute numbers(D) of all N players separated by space.
There is no empty line between different test cases.
Â
Â
For each test case the output will be an integer in a new line, which will be the maximum skill of any non disputed team in the corresponding test case.
Â
1
Input: 3 4 4 1 5 3 1 1 2 0 3 2 10 5 1 1 1 4 8 7 4 6 1 1 1 1 Output: 7 10 13
Explanation:
In 1st test case:
1 has dispute with {2}, 2 has dispute with {3}, 3 has dispute with {4,1} and 4 has dispute with none.
So possible non disputed teams can be:
{1,4} skill=7
{2,3} skill=4
{3} skill=5
Teams {1}, {2}, {4} are also possible.
So maximum skill of any un-disputed team = 7
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll