title: SPOJ MMAXPER::RECTANGLE PERIMETER
body: <p><a href="http://www.spoj.com/problems/MMAXPER/" rel="nofollow">http://www.spoj.com/problems/MMAXPER/</a></p>
  
  <p>I don't know how to approach this problem since I am new to dp problems.
  I am trying this approach but getting wrong answer::</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
    {
      int i,t,l,s,temp;
      long long int sum=0;
      scanf("%d",&amp;t);
      for(i=1;i&lt;=t;i++)
        {
          scanf("%d %d",&amp;s,&amp;l);
          if(s&gt;l) { temp=s; s=l; l=temp }
          if(i==1) sum=sum+l-s;
          else if(i==t &amp;&amp; i%2==0) sum=sum+l+s;
          else if(i==t &amp;&amp; i%2!=0) sum=sum+l-s;
          else if(i%2==0) sum=sum+2*l+s;
          else if(i%2!=0) sum=sum-2*s+l;
        }
      printf("%lld",sum);
      return 0;
    }
  </code></pre>