Beat the Average Solution || Codechef Starters - 37

        

Beat the Average Solution 

Codechef Starters - 37
Problem Code : ABOVEAVG

Solution :

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        ll n, x, m;
        cin >> n >> m >> x;
        ll total = n * x;
        if (x + 1 <= m)
        {
            for (ll i = n - 1; i >= 0; i--)
            {
                ll abovevag = (i) * (x + 1);
                ll belowavg = total - ((i) * (x + 1));
                if (belowavg >= 0)
                {
                    cout << i << "\n";
                    return;
                }
            }
        }
        else
        {
            cout << "0\n";
        }
    }
}

Comments