Maximum money that can be withdrawn in two steps | C ++ implementation of the approach ; Function to return the maximum coins we can get ; Update elements such that X > Y ; Take from the maximum ; Refill ; Again , take the maximum ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxCoins ( int X , int Y ) { if ( X < Y ) swap ( X , Y ) ; int coins = X ; X -- ; coins += max ( X , Y ) ; return coins ; } int main ( ) { int X = 7 , Y = 5 ; cout << maxCoins ( X , Y ) ; return 0 ; }