title: Simplify calculating difference between every element and the elements to its right
body: <p>Can I make it Simpler ?</p>
  
  <pre><code> for(int k=0;k&lt;n;k++)
   for(int l=(k+1);l&lt;n;l++)
   {
       tot+=(max(a[k],a[l])-min(a[k],a[l]));
   }
  </code></pre>
  
  <p>this program is currently taking more time to execute and exceeding the time limit.</p>