maximum subarray variant Problem
There is a circular track containing fuel pits at irregular intervals. The total amount of fuel available from all the pits together is just sufficient to travel round the track and finish where you started. Given the the circuit perimeter, list of each fuel pit location and the amount of fuel they contain, find the optimal start point on the track such that you never run out of fuel and complete circuit.

Sample Input

(location, fuel)

(0/100, 6)
(2,16)
(18,1)
(30,45)
(84,5)
(92,27)


circuit length - 100, total fuel-100
JavaScript 140 chars

For the first solution, I assume that the fuel pits are provided in order order of location around the track and in the form:

var fuelPitInfo = [
    {
       location: 2,//The location from some point on the track
       fuelDistance: 1//The distance you can travel with the fuel from this stop
    },
    ..
]


Thus, a potential non code-golfed JavaScript function to calculate a working starting location is as follows (test fiddle):

function calculateStartingLocation(trackLength, fuelPitInfo) {
    for(i=0;;i++){
        var fuelPit = fuelPitInfo[i];
        var remainingFuelDistance = fuelPit.fuelDistance;
        for(j=i+1;;j++){
            var nextFuelPit = fuelPitInfo[j = j % fuelPitInfo.length];
            if (i == j) return fuelPitInfo[i].location;
            remainingFuelDistance -= (nextFuelPit.location - fuelPit.location + trackLength) % trackLength;
            if (remainingFuelDistance &lt; 0) break;
            remainingFuelDistance += nextFuelPit.fuelDistance;
            fuelPit = nextFuelPit;
        }
    }
}


And the code-golfed function version (140 chars) is as follows (assuming location is replaced with l and fuelDistance is replaced with d in the provided fuelPitInfo object) (test fiddle):

function a(b,c){for(i=0;e=c[i],f=e.d;i++){for(j=i+1;g=c[j=j%c.length];){if(i==j++)return c[i].l;f-=(g.l-e.l+b)%b;if(f&lt;0)break;f+=g.d,e=g;}}}