#B4033. Score Enhancement Challenge

    ID: 11690 Type: Default 1000ms 256MiB

Score Enhancement Challenge

Score Enhancement Challenge

Shunfeng and his good friend have participated in \(n\) exams. In the \(i\)-th exam, Shunfeng originally scores \(a_i\) points while his friend will always score \(b_i\) points. They compare their scores exam‐by‐exam: let \(x\) be the number of exams in which Shunfeng's score is greater than his friend’s, and \(y\) be the number of exams in which his score is lower than his friend’s. The overall result is determined as follows:

  • If \(x > y\), Shunfeng outperforms his friend.
  • If \(x < y\), his friend outperforms him.
  • If \(x = y\), they tie.

Because Shunfeng has the ability to boost his own score by a chosen total increment \(sum\) (distributed arbitrarily among exams), he wants to know the minimum total extra points required to ensure that overall \(x > y\).

Important details:

  • For any exam, if Shunfeng does not boost his score, his result stays at \(a_i\). Note that if \(a_i = b_i\), the exam is considered a tie, contributing neither to \(x\) nor \(y\).
  • Shunfeng can only increase his score; he cannot decrease it.
  • For an exam where \(a_i \le b_i\), in order to secure a win (i.e. make \(a_i + \text{bonus} > b_i\)), he must add at least \(b_i - a_i + 1\) points. However, he may also choose to add just \(b_i - a_i\) points to turn a loss (when \(a_i < b_i\)) into a tie, which avoids a negative contribution (a loss) though it does not count as a win.

Let the initial counts be:

  • \(\text{wins} = \#\{i \mid a_i > b_i\}\)
  • \(\text{losses} = \#\{i \mid a_i < b_i\}\)
  • \(\text{ties} = \#\{i \mid a_i = b_i\}\)

The goal is to choose some exams to boost (possibly converting a loss either to a tie or to a win, and converting a tie to a win) such that the final number of wins \(x'\) and losses \(y'\) satisfy \(x' > y'\). Note that converting a loss to a win gives an improvement of \(2\) in the difference \(x' - y'\) (one more win and one less loss), while converting a tie to a win or a loss to a tie gives an improvement of \(1\). Determine the minimum total extra points needed to achieve \(x' > y'\).

inputFormat

The first line contains an integer \(n\) representing the number of exams. The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\) denoting Shunfeng's original scores. The third line contains \(n\) space-separated integers \(b_1, b_2, \ldots, b_n\) denoting his friend's scores.

outputFormat

Output a single integer — the minimum total extra points Shunfeng needs to distribute in order to achieve overall victory (i.e. turn the exam comparisons such that the number of wins is greater than losses).

sample

3
50 40 70
60 40 80
12