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

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

using namespace std;

#define MAX(x, y) (x > y ? x : y)
#define MIN(x, y) (x < y ? x : y)
#define ABS(x) (x > 0 ? x : -(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int *a, int *b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

void ll_swap(lli *a, lli *b) {
  lli tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int gcd(int a, int b) {
  if (a < b)
    swap(&a, &b);

  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

long power(long x, int n) {
  long ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
    }
    x = x * x;
    n >>= 1;
  }
  return ans;
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
    printf("res:%lld a:%lld\\n", res, a);
  }
  return res;
}

lli comb(lli n, lli r) {
  if (n == 0)
    return 0;

  if (r == 0 || r == n)
    return (1);
  else if (r == 1)
    return (n);
  return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int main() {
  long long int A, B, N;

  scanf("%lld%lld%lld", &A, &B, &N);

  long long int x = MIN(B - 1, N);

  printf("%lld", (A * x) / B - A * (x / B));
}

Error: TLE

Fixed submission:

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

using namespace std;

#define MAX(x, y) (x > y ? x : y)
#define MIN(x, y) (x < y ? x : y)
#define ABS(x) (x > 0 ? x : -(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int *a, int *b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

void ll_swap(lli *a, lli *b) {
  lli tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int gcd(int a, int b) {
  if (a < b)
    swap(&a, &b);

  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

long power(long x, int n) {
  long ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
    }
    x = x * x;
    n >>= 1;
  }
  return ans;
}

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
    printf("res:%lld a:%lld\\n", res, a);
  }
  return res;
}

lli comb(lli n, lli r) {
  if (n == 0)
    return 0;

  if (r == 0 || r == n)
    return (1);
  else if (r == 1)
    return (n);
  return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int main() {
  /*
  int N, M, Q;
  int a[100];
  int b[100];
  int c[100];
  int d[100];

  scanf("%d%d%d", &N, &M, &Q);

  vector<int> num;

  for (int i = 0; i < N; i++)
      num.push_back(1);

  for (int i = 0; i < Q; i++)
      scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
    */

  long long int A, B, N;

  scanf("%lld%lld%lld", &A, &B, &N);

  long long int x = 1;
  long long int temp = 0;
  long long int ans = 0;
  long long int max = -100000000;
  int count = 0;

  // if (B-1 <= N)
  // x = B - 1;

  x = N;

  while (x >= 0 && count <= B + 1) {
    ans = floor((A * x) / B) - A * floor(x / B);
    //   printf("%lld\\n", ans);
    if (ans > max)
      max = ans;
    x--;
    count++;
  }
  // printf("%lld", max);

  printf("%lld", max);
}