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

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

int main() {
  while (true) {
    int count = 0;
    int ax[10000][3] = {0};
    int ai = 0;
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    else {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          if (i != j) {
            for (int k = 1; k <= n; k++) {
              if (i != k && j != k && i + j + k == x) {
                // cout << i << " " << j << " " << k << endl;
                int i2 = i;
                int j2 = j;
                int k2 = k;
                if (i2 > j2) {
                  i2 = j;
                  j2 = i;
                }
                if (j2 > k2) {
                  k2 = j2;
                  j2 = k;
                }
                if (i2 > j2) {
                  int i3 = i2;
                  i2 = j2;
                  j2 = i3;
                }
                if (j2 > k2) {
                  int k3 = k2;
                  k2 = j2;
                  j2 = k3;
                }
                bool is = true;
                for (int c = 0; c < 10000; c++) {
                  if (ax[c][0] == i2 && ax[c][1] == j2 && ax[c][2] == k2) {
                    is = false;
                  }
                }
                if (is) {
                  ax[ai][0] = i2;
                  ax[ai][1] = j2;
                  ax[ai][2] = k2;
                  ai++;
                  count++;
                  // cout << i2 << " " << j2 << " " << k2 << endl;
                }
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int count = 0;
    int ax[100000][3];
    int ai = 0;
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    else {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          if (i != j) {
            for (int k = 1; k <= n; k++) {
              if (i != k && j != k && i + j + k == x) {
                // cout << i << " " << j << " " << k << endl;
                int i2 = i;
                int j2 = j;
                int k2 = k;
                if (i2 > j2) {
                  i2 = j;
                  j2 = i;
                }
                if (j2 > k2) {
                  k2 = j2;
                  j2 = k;
                }
                if (i2 > j2) {
                  int i3 = i2;
                  i2 = j2;
                  j2 = i3;
                }
                if (j2 > k2) {
                  int k3 = k2;
                  k2 = j2;
                  j2 = k3;
                }
                bool is = true;
                for (int c = 0; c < 100000; c++) {
                  if (ax[c][0] == i2 && ax[c][1] == j2 && ax[c][2] == k2) {
                    is = false;
                  }
                }
                if (is) {
                  ax[ai][0] = i2;
                  ax[ai][1] = j2;
                  ax[ai][2] = k2;
                  ai++;
                  count++;
                  // cout << i2 << " " << j2 << " " << k2 << endl;
                }
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }
}