title: Flip cards to get maximum sum
body: <p>Given N cards where if ith card has number x on its front side then it will have -x on back side and a single operation that can be done only once that is to flip any number of cards in consecutive order only once.</p>
  
  <p>Now we need to flip cards in such a way that sum of number of upper face of cards is maximum.</p>
  
  <p>Example : If N=5 and cards[] be {-2,3,-1,-4,-2} then here answer is 8 as we can flip last 3 cards to get configuration {-2,3,1,4,2} which sum to 8.</p>
  
  <p>My Approach :</p>
  
  <p>Go for each possible way for each ith position as start position and find the maximum.But is their any better solution to this problem?</p>
  
  <p>My Code : Am not able to find problem till yet</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  using namespace std;
  int solve(std::vector&lt;int&gt; const &amp; numbers)
  {
      int min_so_far  = numbers[0], min_ending_here = numbers[0];
      size_t begin = 0;
      size_t begin_temp = 0;
      size_t end = 0;
      for(size_t i = 1; i &lt; numbers.size(); i++)
      {
              if(min_ending_here &gt; 0)
              {
                      min_ending_here = numbers[i];
                      begin_temp = i;
              }
              else
              {
                      min_ending_here += numbers[i];
              }
  
              if(min_ending_here &lt;= min_so_far )
              {
                      min_so_far  = min_ending_here;
                      begin = begin_temp;
                      end = i;
              }
      }
      int sum=0;
      for(int i=0;i&lt;begin;i++){
          sum+=numbers[i];
      }
      for(int i=begin;i&lt;=end;i++){
          sum-=numbers[i];
      }
      for(int i=end+1;i&lt;numbers.size();i++){
          sum+=numbers[i];
      }
      return sum;
  
  }
  int main(){
  int n;
  cin&gt;&gt;n;
  vector&lt;int&gt; arr;
  for(int i=0;i&lt;n;i++){
      int x;
      cin&gt;&gt;x;
      arr.push_back(x);
  }
  
    cout&lt;&lt;solve(arr)&lt;&lt;"\n";
  }
  </code></pre>