Problem:
Score : 100 points

Problem Statement

There are two buttons, one of size A and one of size B.

When you press a button of size X, you get X coins and the size of that button decreases by 1.

You will press a button twice. Here, you can press the same button twice, or press both buttons once.

At most how many coins can you get?

Constraints

All values in input are integers.

3 \leq A, B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of coins you can get.

Sample Input 1

5 3

Sample Output 1

9

You can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.

Sample Input 2

3 4

Sample Output 2

7

Sample Input 3

6 6

Sample Output 3

12

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System ; 
 
namespace Program{
 class Program{
  static void Main(string[] args){
   string []buff = Console.ReadLine().Split(' ');
   int N = int.Parse(buff[0]);
   int K = int.Parse(buff[1]);
   
   int count = 0 ;
   int []L = new int[100005];
   int []R = new int[100005];
   
   for(int i = 0 ; i < L.Length ;i++){
     L[i] = -1;
     R[i] = -1;
   }
   string str = Console.ReadLine() ; 
    
   L[0] = 1;
   R[0] = 1;
    
   count++;
    

   for(int i = 0 ;i < N ;i++){
     if( str[i] == '1' && L[count] == -1){
       L[count] = i+1; 
       while( i < N && str[i] == '1'  ){
         i++; 
       }
       R[count] = i  ;
       count++;
     }
   }
   
   L[count] = N ;
   R[count] = N ;
   count++;
    

    
   int index = 0 ;
   int max = 0 ;
   if( count >= 2){
      for(int i = 0 ;i < count - 1 ;i++){
        if( R[i+1] - L[i] > max) index = i;
      }
   }
    
   int left_index = index-1;
   int right_index = index+1;
   
    
   while(K > 0){
     if( right_index >= count && left_index < 0) break;
     
     if( left_index < 0 ){
       R[index] = R[right_index];
       right_index++;
     }else if( right_index >= count){
       L[index] = L[left_index] ;
       left_index--;
     }
     else if(  R[right_index] - L[index] > R[index] - L[left_index] ){
       R[index] = R[right_index];
       right_index++;
     }else{
       L[index] = L[left_index] ;
       left_index--;
     }
 
     K--;
   }
   
 
 
   max = R[index] - L[index] + 1;
   Console.WriteLine(max);
    
  }
 }
}