Count ways to divide C in two parts and add to A and B to make A strictly greater than B | C ++ implementation of the above approach ; Function to count the number of ways to divide C into two parts and add to A and B such that A is strictly greater than B ; Minimum value added to A to satisfy the given relation ; Number of different values of A , i . e . , number of ways to divide C ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countWays ( int A , int B , int C ) { int minAddA = max ( 0 , ( C + B - A + 2 ) / 2 ) ; int count_ways = max ( C - minAddA + 1 , 0 ) ; return count_ways ; } int main ( ) { int A = 3 , B = 5 , C = 5 ; cout << countWays ( A , B , C ) ; return 0 ; }