public int canCompleteCircuit(int[] gas, int[] cost) {
    	int[] r = new int[gas.length];
    	int idx = 0, s = 0, b = -1, ts = 0;
    	for(int i = 0; i<gas.length; i++)
    		r[i] = gas[i] - cost[i];

    	for(idx = 0; idx < r.length; idx++){
    		ts += r[idx];
    		s += r[idx];
    		if(s<0){
    			b = -1;
    			s = 0;
    		}
    		else{
    			if(b == -1)
    				b = idx;
    		}
    	}
    	
    	if(ts<0) return -1;
    	else
    		return b;
        
    }