title: Algorithm to find a number pair's closest match in a list of numbers
body: <p>I have a program with a very specific algorithmic need.  I need to search a list of numbers to find the position in the list that best aligns with a pair of search numbers.  I'm defining 'best aligns' as the sum of the differences at that alignment.</p>
  
  <p>For example, if I have the following list of numbers:</p>
  
  <pre><code>12  18 -20  45  11  34   6  -8
  </code></pre>
  
  <p>...and I'm searching for the pair <strong>44 13</strong>, then the algorithm should return 3, because this alignment is best (has a total difference of only 5), and 3 is the index of where the alignment begins</p>
  
  <pre><code>index:             0   1   2   3   4   5   6   7
  list:             12  18 -20  45  11  34   6  -8
  search alignment: --  --  --  43  14  --  --  -- 
  difference:       --  --  --   2   3  --  --  -- 
  </code></pre>
  
  <p>I'm currently using an obvious brute-force approach - simply finding the difference for each alignment and remembering the best.  However, this is something of a bottleneck for my program, so any improvements would be helpful.</p>
  
  <p>The only optimisation I have come up with is somewhat trivial: if for an alignment the difference for the first number in the pair exceeds the current best total difference, skip to the next alignment without bothering to check the second number in the pair.  It helps, but not much.</p>
  
  <p>If it's relevant, the lists are searched multiple times, so if there's some kind of initial sorting that would speed up future searches, I'd be interested.</p>
  
  <p>I'd appreciate any ideas anyone has, even if it's just a link to a Wikipedia page for a relevant algorithm.  Thanks!</p>