Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// Author- Vaibhav singh
// will be expert soon
//  *#####################################################################################*
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define YES                                                                    \\
  cout << "YES"                                                                \\
       << "\\n";
#define NO                                                                     \\
  cout << "NO"                                                                 \\
       << "\\n";
#define yes                                                                    \\
  cout << "yes"                                                                \\
       << "\\n";
#define no                                                                     \\
  cout << "no"                                                                 \\
       << "\\n";
#define No                                                                     \\
  cout << "No"                                                                 \\
       << "\\n";
#define Yes                                                                    \\
  cout << "Yes"                                                                \\
       << "\\n";
#define f(i, a) for (i = 0; i < a; i++)
#define en "\\n"
#define ull unsigned long long int
#define o(x) cout << x << "\\n";
#define o1(x) cout << x << " ";
#define pb push_back
#define mp make_pair
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t-- > 0)
const ll Mod = 998244353;
#define mod 1000000007
#define re return 0;
// *#######################################################################################*

/*ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
*/

/*void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}  */

// *#########################################################################################*

int main() {
  fast

      ll a,
      b, n;
  cin >> a >> b >> n;
  ll i, mx = 0;
  ll x = min(n, b - 1);
  ll z = floor((a * x) / b) - a * floor(x / b);

  o(z)

      re
}

Error: TLE

Fixed submission:

// Author- Vaibhav singh
// will be expert soon
//  *#####################################################################################*
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define YES                                                                    \\
  cout << "YES"                                                                \\
       << "\\n";
#define NO                                                                     \\
  cout << "NO"                                                                 \\
       << "\\n";
#define yes                                                                    \\
  cout << "yes"                                                                \\
       << "\\n";
#define no                                                                     \\
  cout << "no"                                                                 \\
       << "\\n";
#define No                                                                     \\
  cout << "No"                                                                 \\
       << "\\n";
#define Yes                                                                    \\
  cout << "Yes"                                                                \\
       << "\\n";
#define f(i, a) for (i = 0; i < a; i++)
#define en "\\n"
#define ull unsigned long long int
#define o(x) cout << x << "\\n";
#define o1(x) cout << x << " ";
#define pb push_back
#define mp make_pair
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t-- > 0)
const ll Mod = 998244353;
#define mod 1000000007
#define re return 0;
// *#######################################################################################*

/*ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
*/

/*void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}  */

// *#########################################################################################*

int main() {
  fast

      ll a,
      b, n;
  cin >> a >> b >> n;
  ll i, mx = 0;

  for (i = min(b, n) / 2; i <= min(b, n); i++) {

    ll z = floor((a * i) / b) - a * floor(i / b);
    mx = max(mx, z);
  }

  o(mx)

      re
}