Alice's Sweets
Practice
4.4 (8 votes)
Binary search
Sorting
Algorithms
Problem
69% Success 1694 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Alice has three different types of sweets. There are \(N\) sweets of each type, and each sweet has a tastiness value. The tastiness values for sweets are given in three arrays \(A\), \(B\), and \(C\). The tastiness value of two sweets of a particular type can differ.

Alice wants to choose three sweets, exactly one of each type. Let the chosen sweets’ tastiness values be \(a\), \(b\), and \(c\). You need to choose the sweets such that the value of the equation \(abs(a - b) + abs(b - c) + abs(c - a)\) is minimized. Here, \(abs(x)\) is the absolute value function.

Input Format

  • The first line contains a single integer \(N\) denoting the number of sweets of each type.
  • The second line contains \(N\) space-separated integers denoting the array \(A\).
  • The third line contains \(N\) space-separated integers denoting the array \(B\).
  • The fourth line contains \(N\) space-separated integers denoting the array \(C\).

Output Format

Print the minimum value of the equation mentioned in the problem statement if we can choose exactly one sweet of each type.

Constraints

\(1 \leq N \leq 10^5 \\ 1 \leq A[i], B[i], C[i] \leq 10^8\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Binary search algorithmBinary SearchInput/OutputAlgorithmsBasic ProgrammingBasics of Input/Output
Points:30
17 votes
Tags:
Binary SearchEasySorting
Points:30
2 votes
Tags:
Binary SearchAlgorithms