codeforces-scrape

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

1920B.md (2214B)


      1 Source: https://codeforces.com/problemset/problem/1920/B
      2 
      3 B. Summation Game
      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 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Alice and Bob are playing a game. They have an array $a_1, a_2,\ldots,a_n$. The game consists of two steps:
     22 
     23 * First, Alice will remove at most $k$ elements from the array.
     24 * Second, Bob will multiply at most $x$ elements of the array by $-1$.
     25 
     26 Alice wants to maximize the sum of elements of the array while Bob wants to minimize it. Find the sum of elements of the array after the game if both players play optimally.
     27 
     28 Input
     29 
     30 Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows.
     31 
     32 The first line of each test case contains three integers $n$, $k$, and $x$ ($1 \leq n \leq 2 \cdot 10^5$, $1 \leq x,k \leq n$) — the number of elements in the array, the limit on the number of elements of the array that Alice can remove, and the limit on the number of elements of the array that Bob can multiply $-1$ to.
     33 
     34 The second line of each test case contains $n$ integers $a_1, a_2,\ldots, a_n$ ($1 \leq a_i \leq 1000$) — the elements of the array.
     35 
     36 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     37 
     38 Output
     39 
     40 For each test case, output a single integer — the sum of elements of the array after the game if both players play optimally.
     41 
     42 Example
     43 
     44 Input
     45 
     46 ```
     47 8
     48 
     49 1 1 1
     50 
     51 1
     52 
     53 4 1 1
     54 
     55 3 1 2 4
     56 
     57 6 6 3
     58 
     59 1 4 3 2 5 6
     60 
     61 6 6 1
     62 
     63 3 7 3 3 32 15
     64 
     65 8 5 3
     66 
     67 5 5 3 3 3 2 9 9
     68 
     69 10 6 4
     70 
     71 1 8 2 9 3 3 4 5 3 200
     72 
     73 2 2 1
     74 
     75 4 3
     76 
     77 2 1 2
     78 
     79 1 3
     80 ```
     81 
     82 Output
     83 
     84 ```
     85 0
     86 2
     87 0
     88 3
     89 -5
     90 -9
     91 0
     92 -1
     93 ```
     94 
     95 Note
     96 
     97 In the first test case, it is optimal for Alice to remove the only element of the array. Then, the sum of elements of the array is $0$ after the game is over.
     98 
     99 In the second test case, it is optimal for Alice to not remove any elements. Bob will then multiply $4$ by $-1$. So the final sum of elements of the array is $3+1+2-4=2$.
    100 
    101 In the fifth test case, it is optimal for Alice to remove $9, 9$. Bob will then multiply $5, 5, 3$ by $-1$. So the final sum of elements of the array is $-5-5-3+3+3+2=-5$.