title: getting an error of signed integer overflow(c++)
body: <p>please help me in resolving the error in below code:</p>
  <pre><code>int smallestRangeII(vector&lt;int&gt;&amp; A, int k) {
          sort(A.begin(), A.end());
          int mini = INT_MAX;
          int maxi = INT_MIN;
          int x, y;
          int n = A.size();
          for(int i=0;i&lt;n;i++){
              x = A[i]+k;
              y = A[i]-k;
              if(x &lt;= A[n-1] &amp;&amp; x&lt;=maxi)
                  maxi = x;
              else if(y&gt;=A[0] &amp;&amp; y&gt;=mini)
                  mini = y;
          }
          return (maxi - mini);
      }
  </code></pre>
  <p>I am getting an error of</p>
  <blockquote>
  <p>runtime error: signed integer overflow: -2147483648 - 2147483647
  cannot be represented in type 'int' (solution.cpp) SUMMARY:
  UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:27:22</p>
  </blockquote>
  <p>Thanks in advance</p>