Problem p00999 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long int m[3];
  long long int d, e;
  long long int nn[3];
  while (cin >> m[0] >> m[1] >> m[2] >> d >> e) {
    if (m[0] == 0 && m[1] == 0 && m[2] == 0 && d == 0 && e == 0) {
      break;
    }
    cin >> nn[0] >> nn[1] >> nn[2];
    long long int count = m[0] * nn[0] + m[1] * nn[1] + m[2] * nn[2];
    vector<int> v;
    for (int i = 0; i < nn[2]; i++) {
      v.push_back(m[2]);
    }
    for (int i = 0; i < nn[1]; i++) {
      v.push_back(m[1]);
    }
    for (int i = 0; i < nn[0]; i++) {
      v.push_back(m[0]);
    }
    if (d <= nn[2]) {
      count = m[0] * nn[0] + m[1] * nn[1] + e * nn[2];
    } else if (d <= nn[1] + nn[2]) {
      count =
          min(count, min(m[0] * nn[0] + m[1] * (nn[1] - (d - nn[2])) + e * d,
                         m[0] * nn[0] + m[1] * nn[1] + d * e));
    } else if (d <= nn[0] + nn[1] + nn[2]) {
      count = min(count, min(m[0] * (nn[0] - (d - nn[2] - nn[1])) + e * d,
                             m[0] * nn[0] + m[1] * nn[1] + d * e));
    } else {
      count = min(count, d * e);
    }
    cout << count << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long int m[3];
  long long int d, e;
  long long int nn[3];
  while (cin >> m[0] >> m[1] >> m[2] >> d >> e) {
    if (m[0] == 0 && m[1] == 0 && m[2] == 0 && d == 0 && e == 0) {
      break;
    }
    cin >> nn[0] >> nn[1] >> nn[2];
    vector<vector<vector<long long int>>> dp(
        nn[0] + 1, vector<vector<long long int>>(
                       nn[1] + 1, vector<long long int>(nn[2] + 1)));
    vector<vector<long long int>> mm(100010, vector<long long int>(3));
    /*for (int i = 0; i < 3; i++) {
            for (long long int j = 0; j <= nn[i]; j++) {
                    mm[j][i] = nn[i]*j;
                    if (j >= d) {
                            mm[j][i] = min(mm[j][i], e*j);
                    } else {
                            mm[j][i] = min(mm[j][i], e*d);
                    }
                    for (int k = 0; k <= j; k++) {
                            mm[j][i] = min(mm[j][i], mm[k][i]+mm[j-k][i]);
                    }
            }
    }*/
    for (long long int i = 0; i <= nn[0]; i++) {
      for (long long int j = 0; j <= nn[1]; j++) {
        for (long long int k = 0; k <= nn[2]; k++) {
          dp[i][j][k] = m[0] * i + m[1] * j + m[2] * k;
          if (i + j + k >= d) {
            dp[i][j][k] = min(dp[i][j][k], e * (i + j + k));
          } else {
            dp[i][j][k] = min(dp[i][j][k], e * d);
          }
          if (j > 0) {
            for (long long int l = 1; l <= j; l++) {
              dp[i][j][k] = min(dp[i][j][k], dp[i][j - l][k] + m[1] * l);
            }
          }
          if (i > 0) {
            for (long long int l = 1; l <= i; l++) {
              dp[i][j][k] = min(dp[i][j][k], dp[i - l][j][k] + m[0] * l);
            }
          }
          for (int l = 0; l <= k; l++) {
            dp[i][j][k] = min(dp[i][j][k], dp[i][j][l] + dp[i][j][k - l]);
          }
        }
      }
    }
    cout << dp[nn[0]][nn[1]][nn[2]] << endl;
  }
  return 0;
}