Problem p00523 (C++)

Buggy submission (status: Runtime Error):
// 初めての尺取り

#include <iostream>
#include <stdio.h>
using namespace std;

#define GOMAE (long long)50000
#define EPS (long long)4000
#define TO_OUTSIDE (long long)1500
#define IS_NOT_EVEN_HOBBY (long long)114
int N;
long long input;
long long A[200010];
long long ans;

// A[i]-A[st] >= A[ed]-A[i]となる最小のiを返す。
int seach1(int st, int ed, int i) {

  for (; i < ed; i++) {
    if (A[i] - A[st] >= A[ed] - A[i])
      break;
  }
  return i;
}
// A[i]-A[st] >= Xとなる最小のiを返す。
int seach2(int st, int ed, long long X, int i) {

  for (; i < ed; i++) {
    if (A[i] - A[st] >= X)
      break;
  }
  return i;
}

int solve(long long X) {
  int i, j = 0, k = 0;

  if (X >= (A[N] >> 1))
    return 0;
  for (i = 0; i < N; i++) {
    // 大きさがX以上になるように切る
    for (; j < N + i; j++) {
      if (A[j] - A[i] >= X)
        break;
    }
    // できるだけ真ん中で切る
    for (; k < N + i; k++) {
      if (A[k] - A[j] >= A[N + i] - A[k])
        break;
    }
    if (min(A[j] - A[i], min(A[k] - A[j], A[i + N] - A[k])) >= X)
      break;
    k--;
    if (min(A[j] - A[i], min(A[k] - A[j], A[i + N] - A[k])) >= X)
      break;
  }
  if (i < N)
    return 1;
  return 0;
}

int main() {
  int i, j, k;
  long long s = 0, e = GOMAE * EPS * TO_OUTSIDE * IS_NOT_EVEN_HOBBY * EPS;
  scanf("%d", &N);
  if (N > 100000)
    return 0;

  for (i = 1; i < N + 1; i++) {
    scanf("%d", &input);
    A[i] = A[i - 1] + input;
  }
  for (i = N + 1; i < 3 * N + 1; i++) {
    A[i] = A[i - N] + A[N];
  }

  // printf("%lld %lld\n",s,e);
  while (s <= e) {
    ans = (s + e) >> 1;
    if (solve(ans)) {
      if (solve(ans + 1))
        s = ans + 1;
      else
        break;
    } else {
      e = ans - 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
// 初めての尺取り

#include <iostream>
#include <stdio.h>
using namespace std;

#define GOMAE (long long)50000
#define EPS (long long)4000
#define TO_OUTSIDE (long long)1500
#define IS_NOT_EVEN_HOBBY (long long)114
int N;
long long input;
long long A[300010];
long long ans;

// A[i]-A[st] >= A[ed]-A[i]となる最小のiを返す。
int seach1(int st, int ed, int i) {

  for (; i < ed; i++) {
    if (A[i] - A[st] >= A[ed] - A[i])
      break;
  }
  return i;
}
// A[i]-A[st] >= Xとなる最小のiを返す。
int seach2(int st, int ed, long long X, int i) {

  for (; i < ed; i++) {
    if (A[i] - A[st] >= X)
      break;
  }
  return i;
}

int solve(long long X) {
  int i, j = 0, k = 0;

  if (X >= (A[N] >> 1))
    return 0;
  for (i = 0; i < N; i++) {
    // 大きさがX以上になるように切る
    for (; j < N + i; j++) {
      if (A[j] - A[i] >= X)
        break;
    }
    // できるだけ真ん中で切る
    for (; k < N + i; k++) {
      if (A[k] - A[j] >= A[N + i] - A[k])
        break;
    }
    if (min(A[j] - A[i], min(A[k] - A[j], A[i + N] - A[k])) >= X)
      break;
    k--;
    if (min(A[j] - A[i], min(A[k] - A[j], A[i + N] - A[k])) >= X)
      break;
  }
  if (i < N)
    return 1;
  return 0;
}

int main() {
  int i, j, k;
  long long s = 0, e = GOMAE * EPS * TO_OUTSIDE * IS_NOT_EVEN_HOBBY * EPS;
  scanf("%d", &N);
  if (N > 100000)
    return 0;

  for (i = 1; i < N + 1; i++) {
    scanf("%d", &input);
    A[i] = A[i - 1] + input;
  }
  for (i = N + 1; i < 3 * N + 1; i++) {
    A[i] = A[i - N] + A[N];
  }

  // printf("%lld %lld\n",s,e);
  while (s <= e) {
    ans = (s + e) >> 1;
    if (solve(ans)) {
      if (solve(ans + 1))
        s = ans + 1;
      else
        break;
    } else {
      e = ans - 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}