codeforces-scrape

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

1530C.md (3326B)


      1 Source: https://codeforces.com/problemset/problem/1530/C
      2 
      3 C. Pursuit
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You and your friend Ilya are participating in an individual programming contest consisting of multiple stages. A contestant can get between $0$ and $100$ points, inclusive, for each stage, independently of other contestants.
     22 
     23 Points received by contestants in different stages are used for forming overall contest results. Suppose that $k$ stages of the contest are completed. For each contestant, $k - \lfloor \frac{k}{4} \rfloor$ stages with the highest scores are selected, and these scores are added up. This sum is the overall result of the contestant. (Here $\lfloor t \rfloor$ denotes rounding $t$ down.)
     24 
     25 For example, suppose $9$ stages are completed, and your scores are $50, 30, 50, 50, 100, 10, 30, 100, 50$. First, $7$ stages with the highest scores are chosen — for example, all stages except for the $2$-nd and the $6$-th can be chosen. Then your overall result is equal to $50 + 50 + 50 + 100 + 30 + 100 + 50 = 430$.
     26 
     27 As of now, $n$ stages are completed, and you know the points you and Ilya got for these stages. However, it is unknown how many more stages will be held. You wonder what the smallest number of additional stages is, after which your result might become greater than or equal to Ilya's result, at least in theory. Find this number!
     28 
     29 Input
     30 
     31 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows.
     32 
     33 The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of completed stages.
     34 
     35 The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 100$) — your points for the completed stages.
     36 
     37 The third line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($0 \le b_i \le 100$) — Ilya's points for the completed stages.
     38 
     39 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
     40 
     41 Output
     42 
     43 For each test case print a single integer — the smallest number of additional stages required for your result to be able to become greater than or equal to Ilya's result.
     44 
     45 If your result is already not less than Ilya's result, print $0$.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 5
     53 1
     54 100
     55 0
     56 1
     57 0
     58 100
     59 4
     60 20 30 40 50
     61 100 100 100 100
     62 4
     63 10 20 30 40
     64 100 100 100 100
     65 7
     66 7 59 62 52 27 31 55
     67 33 35 50 98 83 80 64
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 0
     74 1
     75 3
     76 4
     77 2
     78 ```
     79 
     80 Note
     81 
     82 In the first test case, you have scored $100$ points for the first stage, while Ilya has scored $0$. Thus, your overall result ($100$) is already not less than Ilya's result ($0$).
     83 
     84 In the second test case, you have scored $0$ points for the first stage, while Ilya has scored $100$. A single stage with an opposite result is enough for both your and Ilya's overall scores to become equal to $100$.
     85 
     86 In the third test case, your overall result is $30 + 40 + 50 = 120$, while Ilya's result is $100 + 100 + 100 = 300$. After three additional stages your result might become equal to $420$, while Ilya's result might become equal to $400$.
     87 
     88 In the fourth test case, your overall result after four additional stages might become equal to $470$, while Ilya's result might become equal to $400$. Three stages are not enough.