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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll n;
ll a[310];
int dp[301][90001][2];

ll dfs(ll i, ll s, bool f) {
  if (dp[i][s][f] != -1)
    return dp[i][s][f];
  if (i == n) {
    if (!f)
      return dp[n][s][f] = mod_pow(s, n);
    else
      return dp[n][s][f] = (mod - mod_pow(s, n)) % mod;
  }
  ll res = 0;
  if (s >= a[i]) {
    (res += dfs(i + 1, s - a[i], !f)) %= mod;
  }
  (res += dfs(i + 1, s, f)) %= mod;
  return dp[i][s][f] = res;
}

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  ll S;
  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << dfs(0, S, false) << endl;
  return 0;
}


Error: MLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll n;
ll a[310];
ll dp[301][90001][2];

ll dfs(ll i, ll s, bool f) {
  if (dp[i][s][f] != -1)
    return dp[i][s][f];
  if (i == n) {
    if (!f)
      return dp[n][s][f] = mod_pow(s, n);
    else
      return dp[n][s][f] = (mod - mod_pow(s, n)) % mod;
  }
  ll res = 0;
  if (s >= a[i]) {
    (res += dfs(i + 1, s - a[i], !f)) %= mod;
  }
  (res += dfs(i + 1, s, f)) %= mod;
  return dp[i][s][f] = res;
}

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  ll S;
  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << dfs(0, S, false) << endl;
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = c;
  int t = 0;
  while (t < 61) {
    x = x - a;
    if (x <= 0) {
      cout << (c + 60 * t) << endl;
      return 0;
    }
    if (x < b) {
      x = x + 60 - b;
      if (x == c) {
        x = -1;
        cout << x << endl;
        return 0;
      }
      t++;
      continue;
    } else if (x == b) {
      cout << (c + 60 * t) << endl;
      return 0;
    } else {
      x = x - b;
      if (x == c) {
        x = -1;
        cout << x << endl;
        return 0;
      }
      continue;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = c;
  int t = 0;
  if ((a + b) == 60) {
    x = -1;
    cout << x << endl;
    return 0;
  }
  while (1) {
    x = x - a;
    if (x <= 0) {
      cout << (c + 60 * t) << endl;
      return 0;
    }
    if (x < b) {
      x = x + 60 - b;
      t++;
    } else if (x == b) {
      cout << (c + 60 * t) << endl;
      return 0;
    } else {
      x = x - b;
      continue;
    }
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;
/* c++11
#include <tuple>
using std::tuple;
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int main(void) {
  int a;
  int b;
  int c;
  cin >> a >> b >> c;

  int time[60] = {0};
  bool notchange = false;
  int posi = 0;

  while (!notchange) {
    notchange = true;
    while (1) {
      for (int i = posi; i < posi + a; i++) {
        if (time[i] == 0) {
          time[i] = 1;
          notchange = false;
        }
      }
      posi += (a + b);
      if (posi >= 60) {
        posi = posi % 60;
        break;
      }
    }
  }
  /*
  for (int i= 0; i < 60; i++) {
      cout << time[i];
      if (i % 10 == 9) {
          cout << endl;
      }
  }
  */
  if (time[c - 1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int plus = 0;
  int c_temp = c;
  while (1) {
    if (c_temp <= 0) {
      c_temp += 60;
      plus++;
    }
    if (c_temp - a <= 0) {
      cout << c + plus * 60 << endl;
      break;
    }
    c_temp -= (a + b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;
/* c++11
#include <tuple>
using std::tuple;
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int main(void) {
  int a;
  int b;
  int c;
  cin >> a >> b >> c;
  bool repeat = !(60 % (a + b));
  int plus = 0;
  int c_temp = c;
  while (1) {
    if (c_temp <= 0) {
      if (repeat) {
        cout << -1 << endl;
        break;
      } else {
        c_temp += 60;
        plus++;
      }
    }
    if (c_temp - a <= 0) {
      cout << c + plus * 60 << endl;
      break;
    }
    c_temp -= (a + b);
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = -1;
  for (int t = 0; t < 1000; t++) {
    if ((60 * t + c) % (a + b) <= a) {
      ans = 60 * t + c;
      break;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  if ((a + b) % 60 == 0)
    ans = -1;
  else {
    int cnt = 0, t = c;
    while (t < cnt * (a + b) || t > cnt * (a + b) + a) {
      if (t < cnt * (a + b))
        t += 60;
      else
        cnt++;
    }
    ans = t;
  }
  cout << ans << endl;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  if (c % (a + b) <= a) {
    cout << c << endl;
    return 0;
  } else {

    if (60 % (a + b) == 0) {
    L1:
      cout << -1 << endl;
      return 0;
    } else {
      int x = c;
      int t = 0;
      set<int> s;
      while (c % (a + b) > a) {
        c = c % (a + b);
        c += 60;
        t++;
        if (s.count(c) != 0)
          goto L1;
        s.insert(c);
      }
      cout << x + (60 * t) << endl;
      return 0;
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  if (c % (a + b) <= a) {
    cout << c << endl;
    return 0;
  } else {

    if (60 % (a + b) == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      int t = 0;
      while (c % (a + b) > a) {
        c = c % (a + b);
        c += 60;
        t++;
      }
      cout << c + (60 * t) - 60 << endl;
      return 0;
    }
  }
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long int
#define ld long long double
#define reps(i, f, n) for (int i = f; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define m1 cout << "move1" << endl
#define m2 cout << "move2" << endl
#define m3 cout << "move3" << endl
#define m4 cout << "move4" << endl

int main() {
  int flag = 1;
  int a, b, c;
  int t = 0;
  int c_ans;
  int counter = 0;

  cin >> a >> b >> c;
  c_ans = c;

  while (1) {
    counter++;
    if (counter >= 100000) {
      cout << -1 << endl;
      break;
    }
    if (c + 60 * t - a <= 0 && flag == 1) {
      // m1;
      cout << c_ans + 60 * t << endl;
      break;
    }
    // else if(c + 60 * t - a <=0 && flag == 1){
    // t++;
    // flag = 0;
    // }
    else if (c + 60 * t - a >= 0 && flag == 1) {
      // m2;
      c -= a;
      flag = 0;
    } else if (c + 60 * t - b == 0 && flag == 0) {
      // m3;
      cout << c_ans + 60 * t << endl;
      break;
    } else if (c + 60 * t - b < 0 && flag == 0) {
      if (60 % (a + b) == 0) {
        cout << -1 << endl;
        break;
      } else {
        t++;
        flag = 1;
        c -= b;
        // m4;
      }
    } else {
      c -= b;
      flag = 1;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define ld long long double
#define reps(i, f, n) for (int i = f; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define m1 cout << "move1" << endl
#define m2 cout << "move2" << endl
#define m3 cout << "move3" << endl
#define m4 cout << "move4" << endl

int main() {
  int flag = 1;
  int a, b, c;
  int t = 0;
  int c_ans;

  cin >> a >> b >> c;
  c_ans = c;

  while (1) {
    if (c + 60 * t - a <= 0 && flag == 1) {
      // m1;
      cout << c_ans + 60 * t << endl;
      break;
    }
    // else if(c + 60 * t - a <=0 && flag == 1){
    // t++;
    // flag = 0;
    // }
    else if (c + 60 * t - a >= 0 && flag == 1) {
      // m2;
      c -= a;
      flag = 0;
    } else if (c + 60 * t - b == 0 && flag == 0) {
      // m3;
      cout << c_ans + 60 * t << endl;
      break;
    } else if (c + 60 * t - b < 0 && flag == 0) {
      if (60 % (a + b) == 0) {
        cout << -1 << endl;
        break;
      } else {
        t++;
        flag = 1;
        c -= b;
        // m4;
      }
    } else {
      c -= b;
      flag = 1;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX / 2 - 1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, waking = 0, arriving;
  bool flag = false;
  cin >> a >> b >> c;
  arriving = c;
  while (arriving < 3600 + c) {
    while (waking < arriving) {
      if (waking <= arriving && arriving <= waking + a) {
        flag = true;
        break;
      }
      waking += a + b;
    }
    if (flag)
      break;
    arriving += 60;
  }
  if (flag)
    cout << arriving << el;
  else
    cout << "-1" << el;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX / 2 - 1
#define pb push_back

using namespace std;

int main() {
  int a, b, c, waking, arriving;
  bool flag;
  while (cin >> a >> b >> c, a | b | c) {
    waking = 0;
    arriving = c;
    flag = false;
    while (arriving < 3600 + c) {
      while (waking < arriving) {
        if (waking <= arriving && arriving <= waking + a) {
          flag = true;
          break;
        }
        waking += a + b;
      }
      if (flag)
        break;
      arriving += 60;
    }
    if (flag)
      cout << arriving << el;
    else
      cout << "-1" << el;
  }
}
Problem p01751 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  int ans = -1;
  rep(i, 100) {
    int tmp = 60 * i + c;
    if (tmp % (a + b) <= a) {
      ans = tmp;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  if (60 % (a + b) == 0 && c % (a + b) > a)
    cout << -1 << endl;
  else {
    bool f = false;
    rep(i, 65) {
      int tmp = 60 * i + c;
      if (tmp % (a + b) <= a) {
        f = true;
        cout << tmp << endl;
        break;
      }
    }
    assert(f);
  }

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

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int a, b, c;

int main() {
  cin.sync_with_stdio(false);
  cin >> a >> b >> c;
  int time = 0;
  while (1) {
    time += a;
    if (time >= c) {
      time = c;
      break;
    }
    time += b;
    while (time > c)
      c += 60;
    if (time % 60 == 0) {
      time = -1;
      break;
    }
  }
  cout << time << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int a, b, c;

int main() {
  cin.sync_with_stdio(false);
  cin >> a >> b >> c;
  if (a + b == 60 && a < c) {
    cout << -1 << endl;
  } else if (a + b == 60 && a >= c) {
    cout << c << endl;
  } else {
    int time = 0;
    while (1) {
      time += a;
      if (time >= c) {
        time = c;
        break;
      }
      time += b;
      while (time > c)
        c += 60;
    }
    cout << time << endl;
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {

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

  ll ans = c;
  ll tmp = c - 60;
  rep(i, 61) {
    tmp = (tmp + 60) % (a + b);
    if (a < tmp && tmp < a + b)
      ans += 60;
    else {
      cout << ans << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  /*
  if(60 % (a + b) == 0){
          ll tmp = c % (a + b);
          if(a < tmp && tmp < a + b) cout << -1 << endl;
          else cout << c << endl;
  }else{
          ll ans = c;
          while(1){
                  ll tmp = ans % (a + b);
                  if(a < tmp && tmp < a + b) ans += 60;
                  else{
                          cout << ans << endl;
                          break;
                  }
          }
  }
  */

  return 0;
}


Error: TLE

Fixed submission:

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {

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

  if (60 % (a + b) == 0) {
    int tmp = c % (a + b);
    if (a < tmp && tmp < a + b)
      cout << -1 << endl;
    else
      cout << c << endl;
  } else {
    ll ans = c;
    while (1) {
      ll tmp = ans % (a + b);
      if (a < tmp && tmp < a + b)
        ans += 60;
      else {
        cout << ans << endl;
        break;
      }
    }
  }

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

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int now = 0;
  vector<int> visited(60, 0);

  while (1) {
    int t = now % 60;
    if (visited[t]) {
      cout << -1 << endl;
      return 0;
    }
    if (t <= c && c <= t + a) {
      cout << now + c - t << endl;
      return 0;
    }

    visited[t] = 1;
    now = now + a + b;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int awake, asleep, destination;
  cin >> awake >> asleep >> destination;

  int now = 0;
  int a = awake, b = 0;

  while (1) {
    if (now > 60 && (awake + asleep) % 60 == 0) {
      cout << -1 << endl;
      return 0;
    }
    // if( now!=0 && now%60==0 && a==awake ){
    //     cout << -1 << endl;
    //     return 0;
    // }
    if (now % 60 == destination && (a != 0 || (a == 0 && b == asleep))) {
      cout << now << endl;
      return 0;
    }

    if (a) {
      a--;
      now++;
      if (a == 0) {
        b = asleep;
      }
    } else if (b) {
      b--;
      now++;
      if (b == 0) {
        a = asleep;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = c;
  int t = 0;
  while (t < 61) {
    x = x - a;
    if (x <= 0) {
      cout << (c + 60 * t) << endl;
      return 0;
    }
    if (x < b) {
      x = x + 60 - b;
      if (x == c) {
        x = -1;
        cout << x << endl;
        return 0;
      }
      t++;
      continue;
    } else if (x == b) {
      cout << (c + 60 * t) << endl;
      return 0;
    } else {
      x = x - b;
      if (x == c) {
        x = -1;
        cout << x << endl;
        return 0;
      }
      continue;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int x = c;
  int t = 0;
  while (1) {
    x = x - a;
    if (x <= 0) {
      cout << (c + 60 * t) << endl;
      return 0;
    }
    if (x < b) {
      x = x + 60 - b;
      t++;
      if (x == c) {
        x = -1;
        cout << x << endl;
        return 0;
      }
    } else if (x == b) {
      cout << (c + 60 * t) << endl;
      return 0;
    } else {
      x = x - b;
    }
  }
  return 0;
}
Problem p01751 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

signed main() {
  int A = read(), B = read(), C = read();
  int time = 0;
  bool sleep = false;
  int t = 0;
  int i = 0;
  while (i < 10000) {
    time += A;
    if (time >= C) {
      cout << C << endl;
      return 0;
    }
    time += B;
    if (time > C)
      C += 60;

    if (time == 60) {
      cout << -1 << endl;
      return 0;
    }
    i++;
  }

  cout << -1 << endl;
}

Error: TLE

Fixed submission:

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

signed main() {
  int A = read(), B = read(), C = read();
  int time = 0;
  bool sleep = false;
  int t = 0;
  while (true) {
    time += A;
    if (time >= C)
      break;
    time += B;
    if (time > C)
      C += 60;

    if (time == 60) {
      cout << -1 << endl;
      return 0;
    }
  }

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

#include <iostream>
using namespace std;
int main() {
  int n, m, b, d;
  long long c;
  bool a = false;
  cin >> n >> m >> b;
  c = b;
  for (int i = 0; i < 150000000; i++) {
    if (c % (n + m) <= n && a == false) {
      a = true;
      d = i;
    }
    c += 60;
  }
  if (a == false) {
    cout << "-1" << endl;
  } else {
    c = b + d * 60;
    cout << c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, b, d;
  long long c;
  bool a = false;
  cin >> n >> m >> b;
  c = b;
  for (int i = 0; i < 250000000; i++) {
    if (c % (n + m) <= n && a == false) {
      a = true;
      d = i;
    }
    c += 60;
  }
  if (a == false) {
    cout << "-1" << endl;
  } else {
    c = b + d * 60;
    cout << c << endl;
  }
  return 0;
}