Ability Draft
Time limit2sMemory limit512 MB
Given a pick order and ability strengths, find the optimal difference between two teams' total strengths when players draft standard and ultimate abilities in turn.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Dynamic programming, Game theory
- Solved
- No attempts yet
Problem
Dota 2 is a competitive multiplayer computer game. Two teams of players fight each other to destroy the enemy main building, Ancient. Each player controls one hero, and each hero has exactly standard abilities and exactly one ultimate ability.
Ability Draft is a mode of Dota 2. At the start of the game, each player receives a random hero with no abilities. Players then pick abilities in a fixed order from the pool provided by the game. On his turn, a player may pick any remaining standard ability, or, if he has not yet picked his ultimate ability, any remaining ultimate ability. The pool contains enough abilities of both kinds so that each player can always pick his standard abilities and one ultimate ability.
The strength of a team is the sum of the strengths of all abilities of all heroes on that team. Every player picks abilities so that, when the draft ends, the difference between his team's strength and the enemy team's strength is as large as possible.
Given the strengths of the abilities in the pool and the pick order, find the difference between the two teams' strengths when all players pick optimally.
Input
The first line contains two integers and (, ), the number of players in each team and the number of standard abilities per hero.
The second line contains player indices, the pick order. Each index from to appears exactly times in this array. Players with indices from to belong to the first team, and players with indices from to belong to the second team.
The third line contains an integer (), the number of standard abilities in the pool.
The fourth line contains integers from to , the strengths of the standard abilities.
The fifth line contains an integer (), the number of ultimate abilities in the pool.
The sixth line contains integers from to , the strengths of the ultimate abilities.
Output
Output a single integer, the difference between the two teams' strengths after all picks when every player picks optimally.