codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

413C.md (2712B)


      1 Source: https://codeforces.com/problemset/problem/413/C
      2 
      3 C. Jeopardy!
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
     22 
     23 The finals will have *n* questions, *m* of them are auction questions and *n* - *m* of them are regular questions. Each question has a price. The price of the *i*-th question is *a**i* points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price.
     24 
     25 The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again.
     26 
     27 All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve.
     28 
     29 Input
     30 
     31 The first line contains two space-separated integers *n* and *m* (1 ≤ *n*, *m* ≤ 100; *m* ≤ *min*(*n*, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 107) — the prices of the questions. The third line contains *m* distinct integers *b**i* (1 ≤ *b**i* ≤ *n*) — the numbers of auction questions. Assume that the questions are numbered from 1 to *n*.
     32 
     33 Output
     34 
     35 In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 4 1  
     43 1 3 7 5  
     44 3
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 18
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 3 2  
     57 10 3 8  
     58 2 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 40
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 2 2  
     71 100 200  
     72 1 2
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 400
     79 ```