Language: C++

#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

const int INF = 1<<29;

//dpテーブル
int dp[1000][1010];

int calc_mp(int x,int N, int* Len){
  //dpテーブルの初期化
  for (int i = 0; i < 1000; i++) for (int j = 0; j < 1010; j++) dp[i][j] = INF;
  for (int i = 0; i < 1000; i++) for (int k = 0; k < N; k++) dp[i][Len[k]] = 0;

  for (int i = 0; i < 1000; i++){
    for (int l = 0; l < 1010; l++){
      if (l != x){
        if (l >= Len[7]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[7]]+10, dp[i][l-Len[6]]+10, dp[i][l-Len[5]]+10, dp[i][l-Len[4]]+10, dp[i][l-Len[3]]+10, dp[i][l-Len[2]]+10, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[6] && l < Len[7]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[6]]+10, dp[i][l-Len[5]]+10, dp[i][l-Len[4]]+10, dp[i][l-Len[3]]+10, dp[i][l-Len[2]]+10, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[5] && l < Len[6]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[5]]+10, dp[i][l-Len[4]]+10, dp[i][l-Len[3]]+10, dp[i][l-Len[2]]+10, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[4] && l < Len[5]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[4]]+10, dp[i][l-Len[3]]+10, dp[i][l-Len[2]]+10, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[3] && l < Len[4]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[3]]+10, dp[i][l-Len[2]]+10, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[2] && l < Len[3]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[2]]+10, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[1] && l < Len[2]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[1]]+10, dp[i][l-Len[0]]+10});
        else if (l >= Len[0] && l < Len[1]) dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1, dp[i][l-Len[0]]+10});        
        else dp[i+1][l] = min({dp[i][l-1]+1, dp[i][l+1]+1});
      }
      else dp[i+1][l] = dp[i][l];
    }
  }
  return dp[999][x];
}

int main(){
  //入力
  int N;
  cin >> N;
  std::vector<int> ABC(3);
  for (int i = 0; i < 3; i++) cin >> ABC[i];
  std::vector<int> Len(8);
  for (int j = 0; j < N; j++) cin >> Len[j];

  sort(Len.begin(),Len.end());

  cout >> calc_mp(ABC.at(0),N,Len.data()) + calc_mp(ABC.at(1),N,Len.data()) + calc_mp(ABC.at(2),N,Len.data()) >> endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:8: error: 'vector' is not a member of 'std'
   39 |   std::vector<int> ABC(3);
      |        ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | using namespace std;
a.cc:39:15: error: expected primary-expression before 'int'
   39 |   std::vector<int> ABC(3);
      |               ^~~
a.cc:40:38: error: 'ABC' was not declared in this scope
   40 |   for (int i = 0; i < 3; i++) cin >> ABC[i];
      |                                      ^~~
a.cc:41:8: error: 'vector' is not a member of 'std'
   41 |   std::vector<int> Len(8);
      |        ^~~~~~
a.cc:41:8: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:41:15: error: expected primary-expression before 'int'
   41 |   std::vector<int> Len(8);
      |               ^~~
a.cc:42:38: error: 'Len' was not declared in this scope
   42 |   for (int j = 0; j < N; j++) cin >> Len[j];
      |                                      ^~~
a.cc:44:8: error: 'Len' was not declared in this scope
   44 |   sort(Len.begin(),Len.end());
      |        ^~~
a.cc:46:19: error: 'ABC' was not declared in this scope
   46 |   cout >> calc_mp(ABC.at(0),N,Len.data()) + calc_mp(ABC.at(1),N,Len.data()) + calc_mp(ABC.at(2),N,Len.data()) >> endl;
      |                   ^~~