SRM 711 Editorials Contest - Div II - Easy - SquareMaking

Key Information

Register
Submit
The challenge is finished.

Challenge Overview

CHALLENGE OVERVIEW

Welcome to SRM Editorial Challenge! You can now write an Editorial for the SRM  and get featured on the blog, Win a Topcoder Editor T Shirt and yes Cash Prize too.

DETAILED REQUIREMENTS
In this challenge you are required to write an editorial for the SRM 711 problem SquareMaking. Your submission should adhere to the submission guidelines mentioned below.
Problem Area

Problem Statement

You have four sticks. Their lengths are abc, and d. There is also a stick altering store. For one coin they can change (i.e., either increase or decrease) the length of any stick by 1. You can use the store as many times as you want. You would like to build a square out of your four sticks. Therefore, you need four sticks that each have the same length. Note that the length must be positive.

You are given the s abc, and d. Compute and return the smallest number of coins you need to spend at the store.

Limits

Time limit (s):
 
2.000
Memory limit (MB):
 
512

Constraints

a will be between 1 and 1,000,000, inclusive.
b will be between 1 and 1,000,000, inclusive.
c will be between 1 and 1,000,000, inclusive.
d will be between 1 and 1,000,000, inclusive.

Examples

0)
5
6
5
5
Returns: 1
Here the optimal solution is to pay 1 coin to decrease b by 1. After the change you will have four equally long sticks.
1)
4
1
5
4
Returns: 4
Here the optimal side length is 4. Hence, you need to pay the store to increase b three times and to decrease c once. The total amount spent at the store will therefore be 4 coins.
2)
2017
2017
2017
2017
Returns: 0
Here you do not need to change sticks at all.
3)
705451
751563
608515
994713
Returns: 432310
 
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.


PRIZES
---Topcoder Editor T-shirt. If your editorial is published
---Additional cash prizes, once your count of published editorials reaches 10. Please refer below.
---First 10 editorials published, a crash prize of $50.
---Next 15 editorials published, a crash prize of $100.

Once your count of published editorials reaches 25 we will reset the count to 0.


Final Submission Guidelines

---The submission should be a detailed explanation of the solution so that even the new members are able to understand.
---You should also mention the alternative solutions if there are any.
---You have to make yourself available to reply to queries and suggestions in the discussion forum of the SRM.
---The editorial should contain the code for the solution.
---You may attach links to the algorithms explanation and any other relevant resources to make your editorial more understandable.
---Relevant pictures and illustrations are highly recommended.
---You can refer to the following editorials to take inspiration from : https://apps.topcoder.com/wiki/display/tc/Algorithm+Problem+Set+Analysis
---The editorial should be submitted in a text, doc, docx or odt format. 

REVIEW STYLE:

Final Review:

Community Review Board

Approval:

User Sign-Off

SHARE:

ID: 30056957