Problem:
Score : 100 points

Problem Statement

Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.

In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".

The current time is A o'clock, and a contest will begin in exactly B hours.
When will the contest begin? Answer in 24-hour time.

Constraints

0 \leq A,B \leq 23

A and B are integers.

Input

The input is given from Standard Input in the following format:

A B

Output

Print the hour of the starting time of the contest in 24-hour time.

Sample Input 1

9 12

Sample Output 1

21

In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.

Sample Input 2

19 0

Sample Output 2

19

The contest has just started.

Sample Input 3

23 2

Sample Output 3

1

The contest will begin at 1 o'clock the next day.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

int main(int argc, char *argv[])
{
    // x_i -> counts
    map<long long, int> counts;

    int n, a, b;
    cin >> n >> a >> b;

    for (int i = 0; i < n; ++i)
    {
        long long x;
        cin >> x;
        counts[x]++;
    }

    int num_ways = 0;
    double sum = 0;
    for(int k = a; k <= b; ++k)
    {
        int curr_ways = 0;
        double curr_sum = 0;

        int amount_left = k;
        for(auto it = counts.rbegin(); it != counts.rend(); ++it)
        {
            int take = min(it->second, amount_left);
            curr_sum += take * it->first;

            // if we have some left over
            if(it->second >= amount_left)
            {
                curr_ways = it->second - take + 1;
                break;
            }

            amount_left -= take;
        }

        curr_sum /= k;

        if(curr_sum > sum)
        {
            sum = curr_sum;
            num_ways = curr_ways;
        }
        else if(abs(curr_sum - sum) <= 1e-5)
        {
            num_ways += curr_ways;
        }
    }

    cout << fixed << setprecision(6) << sum << endl;
    cout << num_ways << endl;
}