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

#include <iostream>
using namespace std;
int main() {
  int n, s, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    int flag = 0;
    for (int j = 1; j * j < s; j++) {
      int a = s - j;
      int b = 2 * j + 1;
      if (a % b == 0) {
        if (a / b < s) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, s, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    int flag = 0;
    for (int j = 1; j < s; j++) {
      int a = s - j;
      int b = 2 * j + 1;
      if (a % b == 0) {
        if (a / b < s) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool check(int s) {
  for (int i = 1; i <= sqrt(s); i++)
    if ((s - i) % (2 * i + 1) == 0)
      return true;
  return false;
}

int main() {
  int n, cnt = 0, s;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s);
    if (check(s) == false)
      cnt++;
  }
  printf("%d\\n", cnt);
  return 0;
}

Error: TLE

Fixed submission:

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

bool check(double s) {
  double num;
  for (double i = 1; (s - i) >= (2 * i + 1); i++)
    if (modf((s - i) / (2 * i + 1), &num) == 0.0)
      return true;
  return false;
}

int main() {
  int n, cnt = 0;
  double s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lf", &s);
    if (check(s) == false)
      cnt++;
  }
  printf("%d\\n", cnt);
  return 0;
}
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

// -*- coding:utf-8; tab-width:4 -*-
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>

// ティツァツ」テァツュツ?
namespace solution {
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef long long LL;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef set<LL> SET;

const int SIZE = 100001;
int n;
SET S;

struct Solution {
  void init() { S.clear(); }

  bool input() {
    if (!(cin >> n))
      return false;
    for (int i = 0; i < n; ++i) {
      LL a;
      cin >> a;
      S.insert(a);
    }
    return true;
  }

  int solve() {
    int key = 0;
    for (SET::iterator it_i = S.upper_bound(key); it_i != S.end();) {
      key = *it_i;
      for (int i = 1; 2 * i * i + i + i <= key; ++i)
        if ((key - i) % (2 * i + 1) == 0) {
          S.erase(key);
          break;
        }
      it_i = S.upper_bound(key);
    }
    return S.size();
  }

  void output(int result) { cout << result << endl; }

  int run() {
    while (init(), input()) {
      output(solve());
    }
    return 0;
  }
};
} // namespace solution

int main() { return solution::Solution().run(); }

Error: TLE

Fixed submission:

// -*- coding:utf-8; tab-width:4 -*-
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>

// ティツァツ」テァツュツ?
namespace solution {
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef long long LL;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef set<LL> SET;

const int SIZE = 100001;
int n;
SET S;

struct Solution {
  void init() { S.clear(); }

  bool input() {
    if (!(cin >> n))
      return false;
    for (int i = 0; i < n; ++i) {
      LL a;
      cin >> a;
      S.insert(a);
    }
    return true;
  }

  bool check(int s) {
    for (int i = 3; i <= s; i += 2) {
      if ((s - (i - 1) / 2) % i == 0)
        return true;
    }
    return false;
  }

  int solve() {
    int res = S.size();
    for (SET::iterator it_i = S.begin(); it_i != S.end(); ++it_i) {
      if (check(*it_i))
        res--;
    }
    return res;
  }

  void output(int result) { cout << result << endl; }

  int run() {
    while (init(), input()) {
      output(solve());
    }
    return 0;
  }
};
} // namespace solution

int main() { return solution::Solution().run(); }
Problem p00513 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1 << 30;
int main() {
  //	2xy+x+y=A
  //	x(2y+1)=A-y;
  //	x=(A-y)/(2y+1) -> search y
  //  if y<=x then 2y^2+2y<=A -> y^2<=A
  int n;
  cin >> n;
  int out = 0;
  while (n--) {
    ll A;
    cin >> A;
    bool h = false;
    ll y = 1;
    while (y * y <= A) { // A-y>=2*y+1){
      if ((A - y) % (2 * y + 1) == 0) {
        h = true;
        break;
      }
      y++;
    }
    if (!h)
      out++;
  }
  cout << out << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1 << 30;
int main() {
  //	2xy+x+y=A
  //	x(2y+1)=A-y;
  //	x=(A-y)/(2y+1) -> search y
  int n;
  cin >> n;
  int out = 0;
  while (n--) {
    int A;
    cin >> A;
    bool h = false;
    int y = 1;
    while (A - y >= 2 * y + 1) {
      if ((A - y) % (2 * y + 1) == 0) {
        h = true;
        break;
      }
      y++;
    }
    if (!h)
      out++;
  }
  cout << out << endl;
}
Problem p00514 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m, r, a = 1; // a:使用中の配列の数
  cin >> n >> m >> r;
  r -= n * m;
  if (r < 0) {
    cout << 0 << endl;
    return 0;
  }
  int count[6000];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (int i = 1; i != n; i++) { //(r+(n-1))C(n-1)。重複順列。
    for (int j = 0; j < a; j++) {
      count[j] = count[j] * (r + n - i);
    }
    for (int j = a - 1; j >= 0; j--) {
      if (j != 0)
        count[j - 1] += (count[j] % i) * M;
      count[j] = count[j] / i;
    }
    /*オーバーフロー対策*/
    for (int j = 0; j < a; j++) {
      count[j + 1] += count[j] / M;
      count[j] %= M;
    }
    for (a = 6000; count[a - 1] == 0; a--)
      ;
  }
  cout << count[a - 1];
  for (a = a - 2; a >= 0; a--) {
    if (count[a] / 1000 == 0) {
      printf("0");
      if (count[a] / 100 == 0) {
        printf("0");
        if (count[a] / 10 == 0) {
          printf("0");
        }
      }
    }
    cout << count[a];
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int cal(int n, int r) { // 使える色の数、残りのビーズ枠
  /*使える色のうち一色が０〜ｒ個の間の通り数を聞く*/
  if (n == 1 || r == 0) {
    return 1;
  }
  int count = 0;
  for (int i = 0; i <= r; i++) {
    count += cal(n - 1, r - i);
  }
  return count;
}

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  r -= n * m; // 既に確定のものを除く
  if (r < 0) {
    cout << 0 << endl;
    return 0;
  }
  int count = 0;
  for (int i = 0; i <= r; i++) { // ある一色に絞って考える
    count += cal(n - 1, r - i);
  }
  cout << count << endl;
  return 0;
}
Problem p00514 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
typedef long long ll;
int n, m, r;
int now = 1, prev = 0;
ll dp[100001];
ll mod = 1000000;

int main(void) {
  scanf("%d%d%d", &n, &m, &r);
  r -= m * n;
  if (r < 0) {
    puts("0");
    return 0;
  }
  if (r == 0) {
    puts("1");
    return 0;
  }
  int nr = n + r - 1, h = 0;
  dp[0] = 1;
  for (int i = 2; i <= nr; i++) {
    ll p = 0;
    for (int j = 0; j <= h; j++) {
      dp[j] *= i;
      dp[j] += p;
      p = 0;
      if (dp[j] >= mod) {
        if (j == h)
          h++;
        p = dp[j] / mod;
        dp[j] = dp[j] % mod;
      }
    }
  }
  for (int i = 2; i <= r; i++) {
    ll p = 0;
    for (int j = h; j >= 0; j--) {
      dp[j] += mod * p;
      p = dp[j] % i;
      dp[j] = dp[j] / i;
    }
  }
  for (int i = 2; i <= nr - r; i++) {
    ll p = 0;
    for (int j = h; j >= 0; j--) {
      dp[j] += mod * p;
      p = dp[j] % i;
      dp[j] = dp[j] / i;
    }
  }
  bool f = false;
  for (int i = h; i >= 0; i--) {
    if (f)
      printf("%06lld", dp[i]);
    if (!f && dp[i] > 0) {
      f = true;
      printf("%lld", dp[i]);
    }
  }
  printf("\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
typedef long long ll;
int n, m, r;
int now = 1, prev = 0;
ll dp[1001];
ll mod = 1000000;

int main(void) {
  scanf("%d%d%d", &n, &m, &r);
  r -= m * n;
  if (r < 0) {
    puts("0");
    return 0;
  }
  if (r == 0) {
    puts("1");
    return 0;
  }
  int nr = n + r - 1, h = 0;
  dp[0] = 1;
  for (int i = 2; i <= nr; i++) {
    ll p = 0;
    for (int j = 0; j <= h; j++) {
      dp[j] *= i;
      dp[j] += p;
      p = 0;
      if (dp[j] >= mod) {
        if (j == h)
          h++;
        p = dp[j] / mod;
        dp[j] = dp[j] % mod;
      }
    }
  }
  for (int i = 2; i <= r; i++) {
    ll p = 0;
    for (int j = h; j >= 0; j--) {
      dp[j] += mod * p;
      p = dp[j] % i;
      dp[j] = dp[j] / i;
    }
  }
  for (int i = 2; i <= nr - r; i++) {
    ll p = 0;
    for (int j = h; j >= 0; j--) {
      dp[j] += mod * p;
      p = dp[j] % i;
      dp[j] = dp[j] / i;
    }
  }
  bool f = false;
  for (int i = h; i >= 0; i--) {
    if (f)
      printf("%06lld", dp[i]);
    if (!f && dp[i] > 0) {
      f = true;
      printf("%lld", dp[i]);
    }
  }
  printf("\\n");
  return 0;
}
Problem p00515 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int a, temp = 0, x, i;
  for (i = 0; i < 5; i++) {
    scanf("%d", &a);
    if (a >= 40) {
      temp += a;
    } else {
      temp += 40;
    }
  }
  x = temp / 5;
  printf("%d\\n", x);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, temp, x, i;
  for (i = 0; i < 5; i++) {
    scanf("%d", a);
    temp += a;
  }
  x = temp / 5;
  printf("%d\\n", x);
  return 0;
}
Problem p00516 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  while (true) {
    int n, m;
    cin >> n;
    if (cin.eof())
      break;
    cin >> m;

    vector<int> a(1000);
    vector<int> b(1000);
    vector<int> c(1000);
    vector<bool> u(1000);
    vector<int> ans(1000);
    fill(u.begin(), u.end(), true);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    };
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (u[j] && a[i] <= b[j]) {
          u[j] = false;
          ans[i]++;
        }
      }
    }
    int res = -1, ansnum = 0;
    ;
    for (int i = 0; i < n; i++) {
      if (res < ans[i]) {
        res = ans[i];
        ansnum = i + 1;
      }
    }

    cout << ansnum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  vector<bool> u(n);
  vector<int> ans(n);
  fill(u.begin(), u.end(), true);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  };
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (u[j] && a[i] <= b[j]) {
        u[i] = false;
        ans[i]++;
      }
    }
  }
  int res = 0, ansnum = 0;
  ;
  for (int i = 0; i < n; i++) {
    if (res < ans[i]) {
      res = ans[i];
      ansnum = i + 1;
    }
  }

  cout << ansnum << endl;

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, a[5000], b[5000], cnt[5000] = {};
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (a[j] > b[i])
      j++;
    cnt[j]++;
  }
  cout << distance(cnt, max_element(cnt, cnt + n)) + 1 << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, a[1000], b[1000], cnt[1000] = {};
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (a[j] > b[i])
      j++;
    cnt[j]++;
  }
  cout << distance(cnt, max_element(cnt, cnt + n)) + 1 << endl;
}
Problem p00516 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int np[1000];
int mp[1000];
int gp[1000] = {};

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> np[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> mp[i];
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (np[j] <= mp[i]) {
        gp[j]++;
        break;
      }
    }
  }

  int a = 0;
  int b;
  for (int i = 0; i < 1000; i++) {
    if (a < gp[i]) {
      a = gp[i];
      b = i + 1;
    }
  }
  cout << b << endl;

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  vector<int> va, vb, vc;
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    int c;
    cin >> c;
    va.push_back(c);
  }
  for (int i = 0; i < b; i++) {
    int c;
    cin >> c;
    vb.push_back(c);
  }

  for (int i = 0; i < b; i++) {
    for (int j = 0; j < a; j++) {
      if (va[j] <= vb[i]) {
        vc[j] += 1;
        break;
      }
    }
  }
  int d = 0, e = 0;
  for (int i = 0; i < a; i++) {
    if (d < vc[i]) {
      d = vc[i];
      e = i;
    }
  }

  cout << va[e];
  return 0;
}
Problem p00516 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> A(N), B(M);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  vector<int> votes(N);

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] <= B[i]) {
        votes[j]++;
        break;
      }
    }
  }

  int p = 0, best = -1;
  for (int i = 0; i < N; i++) {
    if (best < votes[i]) {
      best = votes[i];
      p = i;
    }
  }

  cout << p + 1 << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> A(N), B(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  vector<int> votes(N);

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] <= B[i]) {
        votes[j]++;
        break;
      }
    }
  }

  int p = 0, best = -1;
  for (int i = 0; i < N; i++) {
    if (best < votes[i]) {
      best = votes[i];
      p = i;
    }
  }

  cout << p + 1 << endl;
}
Problem p00516 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int a[2001], b[2001], c[2001] = {0}, ruio = 0, hideo = 0, nagase = 0,
                        temp = 0;
  scanf("%d %d", &ruio, &hideo);
  for (int i = 1; i <= ruio; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= hideo; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 1; i <= hideo; i++) {
    for (int j = 1; j <= ruio; j++) {
      if (b[i] >= a[j]) {
        nagase = j;
        break;
      }
    }

    c[nagase]++;
    nagase = 0;
  }

  for (int i = 1; i <= ruio; i++) {
    if (nagase < c[i]) {
      nagase = c[i];
      temp = i;
    }
  }

  printf("%d\\n", temp);
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int a[101], b[101], c[101] = {0}, ruio = 0, hideo = 0, nagase = 0, temp = 0;
  scanf("%d %d", &ruio, &hideo);
  for (int i = 1; i <= ruio; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= hideo; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 1; i <= hideo; i++) {
    for (int j = 1; j <= ruio; j++) {
      if (b[i] >= a[j]) {
        nagase = j;
        break;
      }
    }

    c[nagase]++;
    nagase = 0;
  }

  for (int i = 1; i <= ruio; i++) {
    if (nagase < c[i]) {
      nagase = c[i];
      temp = i;
    }
  }

  printf("%d\\n", temp);
}
Problem p00517 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int x[2], y[2];
  cin >> x[0] >> y[0];
  int ans = 0;
  for (int i = 1; i < n; i++) {
    cin >> x[1] >> y[1];
    if (x[0] < x[1] && y[0] < y[1] || x[0] > x[1] && y[0] > y[1]) {
      int kawa = min(abs(x[1] - x[0]), abs(y[1] - y[0]));
      ans += kawa + max(abs(x[1] - x[0]) - kawa, abs(y[1] - y[0]) - kawa);
    } else
      ans += abs(x[0] - x[1]) + abs(y[0] - y[1]);
    x[0] = x[1];
    y[0] = y[1];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 1, 0, -1, -1}, dy[] = {1, 1, 0, -1, -1, 0};
int h, w;
queue<int> quex, quey;
int serch(int clex, int cley, int load, int num);
int main() {
  int n, ans = 0;
  int clex, cley;
  cin >> h >> w >> n;
  cin >> clex >> cley;
  quex.push(clex);
  quey.push(cley);
  for (int i = 0; i < n - 1; i++) {
    cin >> clex >> cley;
    if (quex.front() != clex || quey.front() != cley) {
      ans += serch(clex, cley, 1, 1);
      quex.push(clex);
      quey.push(cley);
    }
  }
  cout << ans << endl;
  return 0;
}
int serch(int clex, int cley, int load, int num) {
  int now = 0;
  for (int i = 0; i < load; i++) {
    int x = quex.front(), y = quey.front();
    quex.pop();
    quey.pop();
    for (int j = 0; j < 6; j++) {
      if (dx[j] + x > 0 && dy[j] + y > 0 && dx[j] + x <= h && dy[j] + y <= w) {
        if (dx[j] + x == clex && dy[j] + y == cley) {
          for (int k = 0; k < now + load - i - 1; k++) {
            quex.pop();
            quey.pop();
          }
          return num;
        } else {
          quex.push(dx[j] + x);
          quey.push(dy[j] + y);
          now++;
        }
      }
    }
  }
  return serch(clex, cley, now, ++num);
}
Problem p00517 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int a[10000], b[10000], w, h;
int solve(int i) {
  int x = 0, y = 0, ans = 0, j;
  x = max(a[i] - a[i + 1], a[i + 1] - a[i]);
  y = max(b[i] - b[i + 1], b[i + 1] - b[i]);
  ans = ans + x + y;
  for (j = 0; j <= min(w, h); j++) {
    if (a[i] - a[i + 1] > j && b[i] - b[i + 1] > j)
      ans--;
    else if (a[i + 1] - a[i] > j && b[i + 1] - b[i] > j)
      ans--;
  }
  return ans;
}
int main() {
  int n, i, answer = 0;
  cin >> w >> h >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  for (i = 1; i < n; i++) {
    answer = solve(i) + answer;
  }
  cout << answer << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int a[100], b[100], w, h;
int solve(int i) {
  int x = 0, y = 0, ans = 0, j;
  x = max(a[i] - a[i + 1], a[i + 1] - a[i]);
  y = max(b[i] - b[i + 1], b[i + 1] - b[i]);
  ans = ans + x + y;
  for (j = 0; j <= min(w, h); j++) {
    if (a[i] - a[i + 1] > j && b[i] - b[i + 1] > j)
      ans--;
    else if (a[i + 1] - a[i] > j && b[i + 1] - b[i] > j)
      ans--;
  }
  return ans;
}
int main() {
  int n, i, answer = 0;
  cin >> w >> h >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  for (i = 1; i < n; i++) {
    answer = solve(i) + answer;
  }
  cout << answer << endl;
  return 0;
}
Problem p00517 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int w, h, n, l = 0, i = 1, x[1001], y[1001];
  cin >> w >> h >> n;
  while (i <= n) {
    cin >> x[i] >> y[i];
    ++i;
  }
  i = 1;
  while (i <= n - 1) {
    if (x[i] <= x[i + 1]) {
      if (y[i] <= y[i + 1]) {
        l = l + max(x[i + 1] - x[i], y[i + 1] - y[i]);
      } else {
        l = l + x[i + 1] - x[i] + y[i] - y[i + 1];
      }
    } else {
      if (y[i] > y[i + 1]) {
        l = l + max(x[i] - x[i + 1], y[i] - y[i + 1]);
      } else {
        l = l + x[i] - x[i + 1] + y[i + 1] - y[i];
      }
    }
    ++i;
  }
  cout << l << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int w, h, n, l = 0, i, x[1001], y[1001];
  cin >> w >> h >> n;
  for (int i; i <= n; ++i) {
    cin >> x[i] >> y[i];
  }
  i = 1;
  while (i <= n - 1) {
    l = l + max(max(x[i] - x[i + 1], x[i + 1] - x[i]),
                max(y[i] - y[i + 1], y[i + 1] - y[i]));
  }
  cout << l << endl;
}