Filling stones
Practice
4.3 (6 votes)
Algorithms
Basics of greedy algorithms
Greedy algorithms
Problem
93% Success 2445 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an integer \(N\). You have total \(2N\) stones numbered from 1 to \(2N\). You have initially two empty arrays of size \(N\) each. You have to fill both the arrays utilizing all the \(2N\) stones and using each stone in only one array.
Let us define the beauty of an array as the difference between the sum of elements at odd positions and the sum of elements at even positions.
The beauty of an array is \(|S1-S2|\) where:
- \(S1 = ∑Ai1\) where \(Ai1\) are the elements positioned at an odd position in an array
- \(S2 = ∑Ai2\) where \(Ai2\) are the elements positioned at an even position in an array
Your task is to arrange the stones in both arrays such that the product of the beauty of both arrays is as minimum as possible.
Input format
A single integer representing \(N\) (\(0<N<10^9\))
Output format
Print that minimum possible product of the beauty of those two arrays.
Submissions
Please login to view your submissions
Similar Problems
Points:10
14 votes
Tags:
Basics of Greedy AlgorithmsGreedy AlgorithmsAlgorithms
Points:10
23 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
3.Subxor
Points:10
48 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Editorial