Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
984 B
7
Indexable
Never
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
class HelloWorld {
    public static long getMinimumMoves(List<Integer> quantity){
        long sum=0l;
        for(int i:quantity){
            sum+=i;
        }
        long half = sum/2, s=0l;
        for(int i=0;i<quantity.size();i++){
            s+=quantity.get(i);
            if(s>half){
                if(i==0 || i==quantity.size()-1)    break;
                return s-(sum-s);
            }else if(s==half){
                return 0;
            }
        }
        if(quantity.get(quantity.size()-1)>half){
            return 2*quantity.get(quantity.size()-1)-sum;
        }
        return quantity.get(quantity.size()-1)-(sum-quantity.get(0));
    }
    public static void main(String[] args) {
        List<Integer> quantity = new ArrayList();
        quantity.add(90);
        quantity.add(90);
        System.out.println(getMinimumMoves(quantity));
    }
}