alexjercan/bugnet huggingface dataset:
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define grt() greater<int>()
#define grtl() greater<long long>()

int main() {
  ll a;
  cin >> a;
  ll b, n;
  cin >> b >> n;

  ll ans = min(n, b - 1);

  std::cout << (a * ans) / b << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define grt() greater<int>()
#define grtl() greater<long long>()

int main() {
  ll a;
  cin >> a;
  ll b, n;
  cin >> b >> n;

  int fb;

  ll cnt = n;
  for (ll i = n; i > 0; i--) {
    fb = i / b;

    if (fb < 1) {
      break;
    }
    cnt--;
  }

  cout << (cnt * a) / b - a * (cnt / b) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

using namespace std;
using ll = long long;
using ull = unsigned long long;

ll func(ll A, ll B, ll x) {
  // return (A * x) / B - A * (x / B);
  return A * (x % B) / B;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll N;
  cin >> N;

  ll ans;
  if (N < B - 1) {
    ans = func(A, B, N);
  } else {
    ans = func(A, B, B - 1);
  }

  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

using namespace std;
using ll = long long;
using ull = unsigned long long;

int func(ll A, ll B, int x) { return (A * x) / B - A * (x / B); }

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll N;
  cin >> N;

  int max_value = 0;
  rep(i, N + 1) { max_value = max(max_value, func(A, B, i)); }

  cout << max_value << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  long long int ans = 0;
  ans = max((a * max(n, b - 1)) / b - a * max(n, b - 1) / b,
            (a * min(n, b - 1)) / b - a * (min(n, b - 1) / b));

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template <class T> T gcd(T a, T b) {
  T m, n, r;
  if (a > b) {
    m = a;
    n = b;
  } else {
    m = b;
    n = a;
  }

  while (n != 0) {
    r = m % n;
    m = n;
    n = r;
  }

  return m;
}
int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  long long int ans = 0;
  for (long long int y = max(n / b - b, 0LL); y <= n; y++) {
    ans = max(ans, (a * y) / b - a * (y / b));
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n, x;
  cin >> a >> b >> n;
  x = min(b - 1, n);
  cout << (a * x / b) - a * (x / b);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long a, b, n, x, max = 0;
  cin >> a >> b >> n;
  for (x = 1; x <= n; x++) {
    int val;
    if ((val = (a * x / b) - a * (x / b)) > max)
      max = val;
  }
  cout << max;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// 注意关键，首先对于这种两个数求差的时候，求最大值的问题，一般需要让第一个数尽量大，第二个数尽量小，由此可以证明极点答案为B的倍数-1
// 还有最简便的办法，就是打表找规律
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
LL a, b, n;
int main() {

  cin >> a >> b >> n;
  LL x = min(b - 1, n);
  cout << a * x / b - a * (x / b);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset((a), 0, sizeof(a))
#define set1(a) memset((a), -1, sizeof(a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector<ps>
#define vpi vector<pi>
#define vpl vector<pl>
#define vpll vector<pll>
#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc(t, T) for (long long t = 0; t < T; t++)
#define rep(i, s, n, d) for (long long i = s; i < n; i = i + d)

bool sortbysec(const pll &a, const pll &b) { return (a.second < b.second); }
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void) {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
void printStack(stack<string> s) {
  if (s.empty())
    return;

  string x = s.top();
  s.pop();
  printStack(s);
  cout << x;
  s.push(x);
}

int main() {

  ll n, a, b, c;
  cin >> a >> b >> n;

  ll left = 1;
  ll right = n;
  ll mid = 1;
  ll min1 = 0;
  ll max1 = 0;
  ll x = 1;
  while (right - left >= 5) {
    mid = (right + left) / 2;
    ll d = (a * mid) / b - a * (mid / b);
    // cout<<d<<endl;
    if (d > max1) {
      max1 = d;
      x = mid;
      left = mid;
    } else
      right = mid;
  }
  for (int i = left; i <= right; i++) {
    ll d = (a * i) / b - a * (i / b);
    if (d > max1) {
      max1 = d;
      x = i;
    }
  }
  cout << max1 << endl;
}

// 1 2 3 1 5 3 1 0 1 0 2
// 1 2 3 4 5 6 7 8 9 10 11
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

#define ll long long

int main() {
  double a, b, n;
  cin >> a >> b >> n;
  double x = min(n, b - 1);
  ll ans = floor((a * x) / b) - a * floor(x / b);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  long long int a, b, n;
  cin >> a >> b >> n;

  /*for (int i = 0; i <= n; i++)
  {
          cout << i << " : " << (a * i) / b - a * (i / b) << endl;
  }*/

  long long int ans = 0;
  for (int i = 0; i <= n; i++) {
    long long int check = ((a * i) / b) - (a * (i / b));
    ans = max(ans, check);
  }

  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
  double a, b, n;

  cin >> a >> b >> n;

  double check = 0;

  int ans = 0;

  if (n >= b - 1) {
    check = b - 1;
    double ax = a * check;
    double bb = ax / b;
    double cc = check / b;
    ans = floor(bb) - a * floor(cc);
    cout << ans << endl;
    return 0;
  }

  else {
    double ax = a * n;
    double bb = ax / b;
    double cc = n / b;
    ans = floor(bb) - a * floor(cc);
    cout << ans << endl;
    return 0;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
  double a, b, n;

  cin >> a >> b >> n;

  int ans = 0;

  double x = 9;

  while (x <= n) {
    double ax = a * x;
    double bb = ax / b;
    double cc = x / b;
    int sum = bb - a * floor(cc);
    ans = max(ans, sum);
    x += 10;
  }

  double check = x - n;

  while (check > 0) {
    double an = a * n;
    double bb = an / b;
    double cc = n / b;
    int sum = bb - a * floor(cc);
    ans = max(ans, sum);
    check--;
    n--;
  }

  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a;
  long long b, n;
  cin >> a >> b >> n;
  long long mn = min(n, b - 1);
  cout << a * mn / b << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  long long A, B, N, X = 0, T;

  cin >> A >> B >> N;

  for (long long I = 0; I <= N; I++) {
    T = floor((A * I) / B) - (A * floor(I / B));
    X = max(X, T);
  }
  cout << X << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define endl '\\n'
#define all(s) s.begin(), s.end()
#define lowbit(x) (x & -x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -1;
  //	for(int i=1;i<=n;i++){
  //		ll now=a*i/b-i/b*a;
  //		if(now>ans) ans=now;
  //		else if(now<ans)
  //	}
  ll pos = b - 1;
  if (n < pos)
    pos = n;
  ans = a * pos / b - pos / b * a;
  cout << ans;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define endl '\\n'
#define all(s) s.begin(), s.end()
#define lowbit(x) (x & -x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -1;
  for (int i = 1; i <= n; i++) {
    ll now = a * i / b - i / b * a;
    if (now > ans)
      ans = now;
    else if (now < ans)
      break;
  }
  cout << ans;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define loop(a, b, c) for (ll a = b; a < c; a++)
#define eloop(a, b, c) for (ll a = b; a <= c; a++)
#define nl printf("\\n")

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0, max = 0, mf = b / a;
  if (b > n) {
    ans = ((a * n) / b);
  } else {
    ans = ((a * (b - 1)) / b);
    /* for(ll i =1; i<b; ){
         ll t = floor((a*i) / b) ;
         if(t > max) max = t;
         i += mf;

     }
     ans = max;
     */
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define loop(a, b, c) for (ll a = b; a < c; a++)
#define eloop(a, b, c) for (ll a = b; a <= c; a++)
#define nl printf("\\n")

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0, max = 0, mf = b / a;
  if (b > n) {
    ans = floor((a * n) / b);
  } else {
    for (ll i = 1; i < b;) {
      ll t = floor((a * i) / b) - (a * floor(i / b));
      if (t > max)
        max = t;
      i += mf;
    }
    ans = max;
  }

  cout << ans << endl;

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int A;
  int64_t B, N;
  cin >> A >> B >> N;
  cout << floor(A * min(B - 1, N) / B) - A * floor(min(B - 1, N) / B) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int A;
  int64_t B, N;
  cin >> A >> B >> N;
  int ans = 0;
  for (int64_t i = 1; i <= min(B, N); ++i) {
    int x = floor(A * i / B) - A * floor(i / B);
    if (x > ans) {
      ans = x;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b < n + 1) {
    ans = (a * (b - 1)) / b;
  } else {
    ans = (a * n) / b - a * (n / b);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b < n) {
    rep(i, b + 1) {
      ll y;
      y = (a * i) / b - a * (i / b);
      ans = max(ans, y);
    }
  } else {
    rep(i, n + 1) {
      ll y;
      y = (a * i) / b - a * (i / b);
      ans = max(ans, y);
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INFTY 1 << 20
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;

int main() {

  ll a, b, n;
  cin >> a >> b >> n;
  ll ok = 0, num; /*
      rep(i,n+1){
          if(ok<(a*i)/b-a*(i/b)){
          num=i;}
          ok = max(ok,(a*i)/b-a*(i/b));
      }
      cout<<"ok"<<ok<<endl;*/
  if (n < b) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  }
  /*
 ll x=b-1,mx=0;
 while(x<=n){
     mx = max(mx,(a*x)/b-a*(x/b));
     x += b;
     cout<<mx<<endl;
 }*/
  if (a - a / b - 1 <= 0)
    cout << 0 << endl;
  else
    cout << a - a / b - 1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INFTY 1 << 20
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;

int main() {

  ll a, b, n;
  cin >> a >> b >> n;
  ll ok = 0, num;
  /*rep(i,n+1){
      if(ok<(a*i)/b-a*(i/b)){
      num=i;}
      ok = max(ok,(a*i)/b-a*(i/b));
  }
  cout<<"ok"<<ok<<endl;*/
  if (n < b) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  }
  ll x = b - 1, mx = 0;
  while (x <= n) {
    mx = max(mx, (a * x) / b - a * (x / b));
    x += b;
  }
  cout << mx << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = -1;

  /*for (int i = 1;i <= n;i++) {
          long long tmp = (long long)floorl(a * i / b) - a * (long long)floorl(i
  / b); ans = max(ans, tmp);
  }

  cout << ans << endl;*/

  if (n >= b - 1 && b != 1) {
    long long i = b - 1;
    ans = (long long)floorl(a * i / b) - a * (long long)floorl(i / b);
  } else {
    long long i = n;
    ans = (long long)floorl(a * i / b) - a * (long long)floorl(i / b);
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = -1;

  for (int i = 1; i <= n; i++) {
    long long tmp = (long long)floorl(a * i / b) - a * (long long)floorl(i / b);
    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2 * acos(0.0)
#define F first
#define S second
#define endl '\\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L + 5;
const int LG = 20;
const int N = 1e5 + 9;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y % 2 == 1)
      res = (res * x) % M;
    x = (x * x) % M;
    y = y / 2;
  }
  return res;
}
bool isvowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' ||
      c == 'E' || c == 'I' || c == 'O' || c == 'U')
    return true;
  return false;
}
int32_t main() {
  // cout.precision(15);
  // cout.setf(ios::fixed,ios::floatfield);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int T = 1;
  // cin>>T;
  while (T--) {
    int i = 0, a, b, n, x;
    cin >> a >> b >> n;
    x = b - 1;
    if (x != 0)
      i = n / (x * b);
    x = max(x, i * x);
    x = min(x, n);
    cout << (a * (x) / b - a * ((x) / b)) << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2 * acos(0.0)
#define F first
#define S second
#define endl '\\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L + 5;
const int LG = 20;
const int N = 1e5 + 9;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y % 2 == 1)
      res = (res * x) % M;
    x = (x * x) % M;
    y = y / 2;
  }
  return res;
}
bool isvowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' ||
      c == 'E' || c == 'I' || c == 'O' || c == 'U')
    return true;
  return false;
}
int32_t main() {
  // cout.precision(15);
  // cout.setf(ios::fixed,ios::floatfield);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int T = 1;
  // cin>>T;
  while (T--) {
    int i = 0, a, b, n, x;
    cin >> a >> b >> n;
    x = b - 1;
    i = n / (x * b);
    x = max(x, i * x);
    x = min(x, n);
    cout << (a * (x) / b - a * ((x) / b)) << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = (a * (min(n, b - 1))) / b;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  vector<ll> A(n, -1);
  ll ans = -1;
  A[0] = 0;
  rep2(i, 1, n) {
    A[i] = (a * i) / b - a * (i / b);
    ans = max(ans, A[i]);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout << x << "\\n";
#define deB(x, y) cout << x << " " << y << "\\n";
#define Deb(x, y, z) cout << x << " " << y << " " << z << "\\n"
#define YES cout << "YES\\n";
#define Yes cout << "Yes\\n";
#define NO cout << "NO\\n";
#define No cout << "No\\n";
#define all(v) (v).begin(), (v).end()
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll a, b, n;
  cin >> a >> b >> n;
  ll i = b - 1, x = b - 1;
  ll ans = (a * n) / b - a * (n / b);
  if (x < n) {
    deb(max(ans, (a * x) / b - a * (x / b)));
  } else {
    deb(ans);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout << x << "\\n";
#define deB(x, y) cout << x << " " << y << "\\n";
#define Deb(x, y, z) cout << x << " " << y << " " << z << "\\n"
#define YES cout << "YES\\n";
#define Yes cout << "Yes\\n";
#define NO cout << "NO\\n";
#define No cout << "No\\n";
#define all(v) (v).begin(), (v).end()
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll a, b, n;
  cin >> a >> b >> n;
  ll i = b - 1;
  ll ans = (a * n) / b - a * (n / b);
  while (i < n) {
    ans = max(ans, (a * i) / b - a * (i / b));
    i += b;
  }
  deb(ans);
}