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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)

using namespace std;

int main()
{
	int n, k; cin >> n >> k;
	string s; cin >> s;

	int segments[2] = { 0, 0 };
	int s_count = 0;

	int max_val = 0;
	int val = 0;
	queue<int> windows;
	bool is_prev_zero = false;
	FOR_LT(i, 0, s.size()) {
		bool is_zero = (s[i] == '0');
		if (is_prev_zero != is_zero) {
			if (s_count & 1) {
				if (windows.size() == k) {
					max_val = max(max_val, val);

					val -= windows.front();
					windows.pop();
				}
				windows.push(segments[1] + segments[0]);
			}
			val += segments[s_count & 1];
			s_count++;
			segments[s_count & 1] = 0;
		}
		segments[s_count & 1]++;
		is_prev_zero = is_zero;
	}
	if (s_count & 1) {
		if (windows.size() == k) {
			max_val = max(max_val, val);
			val -= windows.front();
		}
	}
	val += segments[s_count & 1];
	max_val = max(max_val, val);

	cout << max_val << endl;

	return 0;
}