Equal multisets
Practice
4 (99 votes)
Ad Hoc
Basic math
Easy
簡単
Mathematics
Mathematics
Problem
87% Success 17951 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given two multisets \(A\) and \(B\), each containing \(N\) elements. In one step, you can choose an integer \(x\) from \(A\), delete an occurrence of \(x\) from \(A\), and add either \(x+1\) or \(x - 1\) to \(A\). Determine the minimum number of moves required such that the condition \(A = B\) satisfies.
Input format
- First line: Integer \(N\) \((1 \le N \le 10^5)\)
- Second line: \(N\) integers that represent the multiset \(A\)
- Third line: \(N\) integers that represent the multiset \(B\)
Note: All the numbers are positive integers smaller or equal to \(2^{63} - 1\).
Output format
Print the remainder of the answer when divided by \(10^9 + 7\).
Submissions
Please login to view your submissions
Similar Problems
Points:20
56 votes
Tags:
Ad-HocEasyMath
Points:20
132 votes
Tags:
ReadyMathematicsOpenApprovedEasyMathamatics
Points:20
11 votes
Tags:
Easy
Editorial