Problem p03071 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>

int main() {
  int a, b;
  int ans[21][21] = {
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  6,  7,  9,  11, 13, 15,
      17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,  7,  8,  9,
      11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,
      9,  9,  10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39,
      0,  0,  0,  11, 11, 11, 12, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33,
      35, 37, 39, 0,  0,  0,  13, 13, 13, 13, 14, 15, 17, 19, 21, 23, 25, 27,
      29, 31, 33, 35, 37, 39, 0,  0,  0,  15, 15, 15, 15, 15, 16, 17, 19, 21,
      23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,  17, 17, 17, 17, 17, 17,
      18, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,  19, 19, 19,
      19, 19, 19, 19, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,
      21, 21, 21, 21, 21, 21, 21, 21, 22, 23, 25, 27, 29, 31, 33, 35, 37, 39,
      0,  0,  0,  23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 25, 27, 29, 31, 33,
      35, 37, 39, 0,  0,  0,  25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 27,
      29, 31, 33, 35, 37, 39, 0,  0,  0,  27, 27, 27, 27, 27, 27, 27, 27, 27,
      27, 27, 28, 29, 31, 33, 35, 37, 39, 0,  0,  0,  29, 29, 29, 29, 29, 29,
      29, 29, 29, 29, 29, 29, 30, 31, 33, 35, 37, 39, 0,  0,  0,  31, 31, 31,
      31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 33, 35, 37, 39, 0,  0,  0,
      33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 35, 37, 39,
      0,  0,  0,  35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
      36, 37, 39, 0,  0,  0,  37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
      37, 37, 37, 37, 38, 39, 0,  0,  0,  39, 39, 39, 39, 39, 39, 39, 39, 39,
      39, 39, 39, 39, 39, 39, 39, 39, 40};
  /*int aa, ab, bb;
  for (int i = 3; i < 21; ++i)
  {
      for (int j = 3; j < 21; ++j)
      {
          res = 0;
          aa = i + i - 1;
          ab = i + j;
          bb = j + j - 1;
          res = max(res, aa);
          res = max(res, ab);
          res = max(res, bb);
          ans[i][j] = res;
      }
  }
  for (int i = 0; i < 21; ++i)
  {
      for (int j = 0; j < 21; ++j)
      {
          cout << ans[i][j] << ",";
      }
  }*/
  while (scanf("%d%d", &a, &b)) {
    printf("%d\n", ans[a][b]);
  }
  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  int a, b;
  int ans[21][21] = {
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  6,  7,  9,  11, 13, 15,
      17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,  7,  8,  9,
      11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,
      9,  9,  10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39,
      0,  0,  0,  11, 11, 11, 12, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33,
      35, 37, 39, 0,  0,  0,  13, 13, 13, 13, 14, 15, 17, 19, 21, 23, 25, 27,
      29, 31, 33, 35, 37, 39, 0,  0,  0,  15, 15, 15, 15, 15, 16, 17, 19, 21,
      23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,  17, 17, 17, 17, 17, 17,
      18, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,  19, 19, 19,
      19, 19, 19, 19, 20, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 0,  0,  0,
      21, 21, 21, 21, 21, 21, 21, 21, 22, 23, 25, 27, 29, 31, 33, 35, 37, 39,
      0,  0,  0,  23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 25, 27, 29, 31, 33,
      35, 37, 39, 0,  0,  0,  25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 27,
      29, 31, 33, 35, 37, 39, 0,  0,  0,  27, 27, 27, 27, 27, 27, 27, 27, 27,
      27, 27, 28, 29, 31, 33, 35, 37, 39, 0,  0,  0,  29, 29, 29, 29, 29, 29,
      29, 29, 29, 29, 29, 29, 30, 31, 33, 35, 37, 39, 0,  0,  0,  31, 31, 31,
      31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 33, 35, 37, 39, 0,  0,  0,
      33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 35, 37, 39,
      0,  0,  0,  35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
      36, 37, 39, 0,  0,  0,  37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
      37, 37, 37, 37, 38, 39, 0,  0,  0,  39, 39, 39, 39, 39, 39, 39, 39, 39,
      39, 39, 39, 39, 39, 39, 39, 39, 40};
  /*int aa, ab, bb;
  for (int i = 3; i < 21; ++i)
  {
      for (int j = 3; j < 21; ++j)
      {
          res = 0;
          aa = i + i - 1;
          ab = i + j;
          bb = j + j - 1;
          res = max(res, aa);
          res = max(res, ab);
          res = max(res, bb);
          ans[i][j] = res;
      }
  }
  for (int i = 0; i < 21; ++i)
  {
      for (int j = 0; j < 21; ++j)
      {
          cout << ans[i][j] << ",";
      }
  }*/
  while (scanf("%d%d", &a, &b) != EOF) {
    printf("%d\n", ans[a][b]);
  }
  return 0;
}