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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(a, b)                                                            \\
  if ((a) > (b))                                                               \\
    (a) = (b);
#define chmax(a, b)                                                            \\
  if ((a) < (b))                                                               \\
    (a) = (b);
#define vi vector<int>
#define pii pair<int, int>
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define pf push_front
int gcd(int a, int b) { /*a>=0,b>=0,￢(a=b=0)*/
  while (min(a, b) > 0) {
    if (a < b)
      swap(a, b);
    a %= b;
  }
  return max(a, b);
}
int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;

/*----------------------------------------------*/

signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int x = b - 1;
  int ans = -1;

  if (b - 1 >= n)
    ans = (a * n) / b;
  else {
    x = n - n % b - 1;
    if (n % b == b - 1)
      x = n;
    ans = (a * x) / b - a * (x / b);
  }
  cout << ans << endl;
  return 0;
}

// signed main(){
//   int n,m,q;
//   cin>>n>>m>>q;
//   vi a(q),b(q),c(q),d(q);
//   rep(i,q) cin>>a[i]>>b[i]>>c[i]>>d[i];

//   int ans=0;

//   rep(bit,(1<<10)){
//     int tmp=bit;
//     vi a;
//     rep(i,n)

//   }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(a, b)                                                            \\
  if ((a) > (b))                                                               \\
    (a) = (b);
#define chmax(a, b)                                                            \\
  if ((a) < (b))                                                               \\
    (a) = (b);
#define vi vector<int>
#define pii pair<int, int>
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pb push_back
#define pf push_front
int gcd(int a, int b) { /*a>=0,b>=0,￢(a=b=0)*/
  while (min(a, b) > 0) {
    if (a < b)
      swap(a, b);
    a %= b;
  }
  return max(a, b);
}
int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;

/*----------------------------------------------*/

signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int x = b - 1;
  int ans = -1;
  for (x = b - 1; x <= n; x += b) {
    chmax(ans, (a * x / b) - a * (x / b));
  }
  if (b - 1 > n)
    ans = (a * n) / b;
  cout << ans << endl;
  return 0;
}

// signed main(){
//   int n,m,q;
//   cin>>n>>m>>q;
//   vi a(q),b(q),c(q),d(q);
//   rep(i,q) cin>>a[i]>>b[i]>>c[i]>>d[i];

//   int ans=0;

//   rep(bit,(1<<10)){
//     int tmp=bit;
//     vi a;
//     rep(i,n)

//   }

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