- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to find minimum difference between concerts durations

Suppose we have three numbers a, b and c. A singer has 'a' one-minute songs, 'b' tow-minutes song and 'c' three-minutes song. He wants to distribute all songs into two concerts, such that every song should be included to exactly one concert. He wants to make the absolute difference of durations of the concerts as small as possible. The duration of the concert is the sum of durations of all songs in that concert. We have to find the minimal possible difference between the concerts durations.

So, if the input is like a = 2; b = 1; c = 3, then the output will be 1, because he can include two one-minute songs and one two-minute song and one three-minute song into the first concert, and two three-minute songs into the second concert. First concert duration will be 1 + 1 + 2 + 3 = 7, the duration of the second concert will be 6. The difference of them is |7 − 6| = 1.

## Steps

To solve this, we will follow these steps −

return (a + (1 if c is odd, otherwise 0))

## Example

Let us see the following implementation to get better understanding −

#include<bits/stdc++.h> using namespace std; int solve(int a, int b, int c){ return (a+c&1); } int main(){ int a = 2; int b = 1; int c = 3; cout << solve(a, b, c) << endl; }

## Input

2, 1, 3

## Output

1

- Related Questions & Answers
- C++ Program to find minimum difference between strongest and weakest
- C++ code to find minimum arithmetic mean deviation
- Find minimum difference between any two element in C++
- C++ code to find minimum stones after all operations
- C++ code to find minimum different digits to represent n
- C++ code to find minimum jump to reach home by frog
- C++ code to find minimum time needed to do all tasks
- C++ code to find minimum moves with weapons to kill enemy
- Program to find minimum difference between two elements from two lists in Python
- C++ code to find minimum correct string from given binary string
- Find the minimum difference between Shifted tables of two numbers in Python
- C++ code to find minimum operations to make numbers c and d
- C++ code to find minimum k to get more votes from students
- Difference between Managed and Unmanaged code in .NET
- Program to find minimum absolute sum difference in Python