codeforces-scrape

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

2157D.md (2974B)


      1 Source: https://codeforces.com/problemset/problem/2157/D
      2 
      3 D. Billion Players Game
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 [NemesisTheory - Rose At Nightfall](https://soundcloud.com/pyrk13/rose-at-nightfall)
     22 
     23 ⠀
     24 
     25 You are following the world championship of the Billion Players Game. There are $10^9$ players competing, and you want to predict the final ranking $p$ of Godflex, your favorite streamer. After analyzing recent matches, you are sure that $l \leq p \leq r$, but you don't know anything else.
     26 
     27 There are $n$ offers made by the in-game bookmaker. In the $i$-th offer, the bookmaker suggests an estimation $a_i$ for Godflex's final ranking. For each offer, you must choose exactly one of the following actions:
     28 
     29 * Ignore the offer.
     30 * Accept the offer by claiming that $p \leq a_i$. If you are right, you earn $|p-a_i|$ robocoins; otherwise you lose $|p-a_i|$ robocoins.
     31 * Accept the offer by claiming that $p \geq a_i$. If you are right, you earn $|p-a_i|$ robocoins; otherwise you lose $|p-a_i|$ robocoins.
     32 
     33 After you decide how to deal with all the offers, the actual Billion Players Game is played. Godflex gets a position $p$ in $[l, r]$, and then all the offers are settled up.
     34 
     35 Your total score is the number of robocoins you are guaranteed to earn, that is, the minimum number of robocoins you earn over all possible values of $p$ in $[l, r]$. Find the maximum possible score you can guarantee.
     36 
     37 Input
     38 
     39 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
     40 
     41 The first line of each test case contains three integers $n$, $l$, $r$ ($1 \leq n \leq 2 \cdot 10^5$, $1 \leq l \leq r \leq 10^9$) — the number of offers and the possible range of Godflex's final ranking.
     42 
     43 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the bookmaker's estimations of Godflex's ranking in each offer.
     44 
     45 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     46 
     47 Output
     48 
     49 For each test case, output a single line containing an integer: the maximum possible score you can guarantee.
     50 
     51 Example
     52 
     53 Input
     54 
     55 ```
     56 4
     57 
     58 1 1 5
     59 
     60 3
     61 
     62 2 100 100
     63 
     64 50 200
     65 
     66 5 1 10
     67 
     68 5 7 3 9 1
     69 
     70 5 6 10
     71 
     72 9 3 1 7 5
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 0
     79 
     80 150
     81 
     82 12
     83 
     84 13
     85 ```
     86 
     87 Note
     88 
     89 In the first test case, there is only one offer.
     90 
     91 * If you ignore the offer, your score is $0$;
     92 * if you accept the offer claiming that $p \leq 3$, your score is $-2$ (reached when $p = 5$, which makes you lose $|5-3| = 2$ robocoins);
     93 * if you accept the offer claiming that $p \geq 3$, your score is $-2$ (reached when $p = 1$, which makes you lose $|1-3| = 2$ robocoins).
     94 
     95 So the maximum possible score is $0$.
     96 
     97 In the second test case, it is optimal to accept the offers claiming that $p \geq 50$ and $p \leq 200$. Since $p$ must be $100$, you gain $|100-50| + |100-200| = 150$ robocoins.