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

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

using namespace std;
// using namespace __gnu_pbds;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, arr, n) for (int i = arr; i <= n; i++)
#define repd(i, arr, n) for (int i = arr; i >= n; i--)
#define trav(arr, x) for (auto &arr : x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000 * 1000 * 1000 + 7)
#define vi vector<int>
#define pii pair<int, int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define endl "\\n"

// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;

const int mod = 1e10 + 7;
double power(double a, int b) {
  double ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a);
    }
    a = (a * a);
    b >>= 1;
  }
  return ans;
}

int32_t main() {
  fast;

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

  map<int, int> mpp;
  int val = min(b - 1, n);
  int maxx = a * (val % b) - (a * val) % b;
  maxx /= b;
  cout << maxx << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

using namespace std;
// using namespace __gnu_pbds;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, arr, n) for (int i = arr; i <= n; i++)
#define repd(i, arr, n) for (int i = arr; i >= n; i--)
#define trav(arr, x) for (auto &arr : x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000 * 1000 * 1000 + 7)
#define vi vector<int>
#define pii pair<int, int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define endl "\\n"

// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;

const int mod = 1e10 + 7;
double power(double a, int b) {
  double ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a);
    }
    a = (a * a);
    b >>= 1;
  }
  return ans;
}

int32_t main() {
  fast;

  int a, b, n, maxx = 0;
  cin >> a >> b >> n;

  map<int, int> mpp;

  repd(i, min(n, b - 1), 1) {
    int val1 = a * (i % b);
    int val2 = (a * i) % b;

    if (mpp[val2]) {
      break;
    }
    // cout<<i<<" "<<val1<<" "<<val2<<endl;
    mpp[val2]++;
    maxx = max((val1 - val2) / b, maxx);
  }

  cout << maxx << endl;
}