Problem p03162 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <deque> //<< fixed << setprecision()
#include <iomanip>
#include <iostream>
#include <map>
#include <queue> //priority_queue
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point {
  long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
  double a =
      (x2 * y3) - (x3 * y2) - (x1 * y3) + (x3 * y1) + (x1 * y2) - (x2 * y1);
  a /= 2;
  return fabs(a);
}

long double anyarea(point p[], int n) {
  long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
  for (int i = 0; i < n - 1; i++) {
    sum1 += p[i].x * p[i + 1].y;
    sum2 += p[i].y * p[i + 1].x;
  }
  return fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m) {
  if (p == 0)
    return 1;
  ll ans = fastpow(base, p / 2, m);
  ans = ((ans % m) * (ans % m)) % m;
  if (p % 2)
    ans = ((base % m) * ans) % m;
  return ans;
}
ll GCD(ll M, ll m) {
  if (M % m == 0)
    return m;
  M %= m;
  ll x1 = M, x2 = m;
  m = min(x1, x2);
  M = max(x1, x2);
  return GCD(M, m);
}
ll lcm(ll M, ll m) { return (M * m) / GCD(max(M, m), min(M, m)); }

int main() {
  int n;
  int arr[100][3], ans[100][3] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {

      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    int m[3] = {};
    for (int j = 0; j < 3; j++) {
      if (i == 0)
        ans[i][j] = arr[i][j];
      else {
        if (j != 0)
          m[0] = max(m[0], ans[i - 1][j]);
        if (j != 1)
          m[1] = max(m[1], ans[i - 1][j]);
        if (j != 2)
          m[2] = max(m[2], ans[i - 1][j]);
      }
    }
    for (int j = 0; j < 3; j++) {
      ans[i][j] = m[j] + arr[i][j];
    }
  }
  int res = 0;
  res = max(ans[n - 1][0], max(ans[n - 1][2], ans[n - 1][1]));
  cout << res;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <deque> //<< fixed << setprecision()
#include <iomanip>
#include <iostream>
#include <map>
#include <queue> //priority_queue
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

struct point {
  long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
  double a =
      (x2 * y3) - (x3 * y2) - (x1 * y3) + (x3 * y1) + (x1 * y2) - (x2 * y1);
  a /= 2;
  return fabs(a);
}

long double anyarea(point p[], int n) {
  long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
  for (int i = 0; i < n - 1; i++) {
    sum1 += p[i].x * p[i + 1].y;
    sum2 += p[i].y * p[i + 1].x;
  }
  return fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m) {
  if (p == 0)
    return 1;
  ll ans = fastpow(base, p / 2, m);
  ans = ((ans % m) * (ans % m)) % m;
  if (p % 2)
    ans = ((base % m) * ans) % m;
  return ans;
}
ll GCD(ll M, ll m) {
  if (M % m == 0)
    return m;
  M %= m;
  ll x1 = M, x2 = m;
  m = min(x1, x2);
  M = max(x1, x2);
  return GCD(M, m);
}
ll lcm(ll M, ll m) { return (M * m) / GCD(max(M, m), min(M, m)); }

int main() {
  int n;
  int arr[100005][3], ans[100005][3] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {

      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    int m[3] = {};
    for (int j = 0; j < 3; j++) {
      if (i == 0)
        ans[i][j] = arr[i][j];
      else {
        if (j != 0)
          m[0] = max(m[0], ans[i - 1][j]);
        if (j != 1)
          m[1] = max(m[1], ans[i - 1][j]);
        if (j != 2)
          m[2] = max(m[2], ans[i - 1][j]);
      }
    }
    for (int j = 0; j < 3; j++) {
      ans[i][j] = m[j] + arr[i][j];
    }
  }
  int res = 0;
  res = max(ans[n - 1][0], max(ans[n - 1][2], ans[n - 1][1]));
  cout << res;
}