The First Cry of Atom

Marble problem

I tried this problem.


There are boxes infinitely in a straight line. Each box is labeled from left side …,-2,-1,0,1,2,… to the right side. Now R red marbles are in the -100th box. In the same way, G green mables are in the 0th box and B blue mables are in the 100th box. There no other marbles in all boxes. All boxes should have one marble at most. Repeat below process and make the number of marbles of each each at most one.

Calculate minimum required steps.

I wrote below code.

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

 * Created by sasakiumi on 3/18/14.
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(;

        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int max = Math.max(Math.max(r, g), b);
        List<Integer> steps = new ArrayList<Integer>();
            Integer pre = steps.get(i - 1);
            steps.add(pre + (i / 2));
        Integer ans = steps.get(r) + steps.get(g) + steps.get(b);

OK. I understand this code does not put the case of 100 marbles that is same color into consideration. If there are 200 red marbles, this code does not work properly. But I have not found effective way to solve all cases. I will update this problem later. If you have any good idea, please let me know.

Thank you.