Language: C++

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
 
using namespace std;
 
int n, a, b, c;
vector<int> l;
 
int inf = 1e9;
 
int dfs(int v, int aa, int bb, int cc, const vector<int>& l)
{
    int ret = inf;
    if (v == n)
    {
        if (aa > 0 && bb > 0 && cc > 0)
        {
            return (abs(a - aa) + abs(b - bb) + abs(c - cc) - 30);
        }
        return ret;
    }
    for (int i = 0; i < 4; ++i)
    {
        if (i == 0)
        {
            ret = min(ret, dfs(v + 1, aa, bb, cc, l));
        }
        else if (i == 1)
        {
            ret = min(ret, dfs(v + 1, aa + l[v], bb, cc, l) + 10);
        }
        else if (i == 2)
        {
            ret = min(ret, dfs(v + 1, aa, bb + l[v], cc, l) + 10);
        }
        else
        {
            ret = min(ret, dfs(v + 1, aa, bb, cc + l[v], l) + 10);
        }
    }
    
    return ret;
}
 
int main() {
    
    cin >> n >> a >> b >> c;
    
    l = vector<int>(n, 0);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> l[i];
    }
    
    int ret = dfs(0, 0, 0, 0, l);
    
    cout << ret << endl;
    
    return 0;
}
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int n, a, b, c;
vector<int> l;

int inf = 1e9;

int dfs(int v, int aa, int bb, int cc, const vector<int>& l)
{
    int ret = inf;
    if (v == n)
    {
        if (aa > 0 && bb > 0 && cc > 0)
        {
            return (abs(a - aa) + abs(b - bb) + abs(c - cc) - 30);
        }
        return ret;
    }
    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            ret = min(ret, dfs(v + 1, aa, bb, cc, l));
        }
        else if (i == 1)
        {
            ret = min(ret, dfs(v + 1, aa + l[v], bb, cc, l) + 10);
        }
        else if (i == 2)
        {
            ret = min(ret, dfs(v + 1, aa, bb + l[v], cc, l) + 10);
        }
        else if (i == 3)
        {
            ret = min(ret, dfs(v + 1, aa, bb, cc + l[v], l) + 10);
        }
    }
    
    return ret;
}

int main() {
    
    cin >> n >> a >> b >> c;
    
    l = vector<int>(n, 0);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> l[i];
    }
    
    int ret = dfs(0, 0, 0, 0, l);
    
    cout << ret << endl;
    
    return 0;
}



Compiler output:
a.cc:83:5: error: redefinition of 'int n'
   83 | int n, a, b, c;
      |     ^
a.cc:14:5: note: 'int n' previously declared here
   14 | int n, a, b, c;
      |     ^
a.cc:83:8: error: redefinition of 'int a'
   83 | int n, a, b, c;
      |        ^
a.cc:14:8: note: 'int a' previously declared here
   14 | int n, a, b, c;
      |        ^
a.cc:83:11: error: redefinition of 'int b'
   83 | int n, a, b, c;
      |           ^
a.cc:14:11: note: 'int b' previously declared here
   14 | int n, a, b, c;
      |           ^
a.cc:83:14: error: redefinition of 'int c'
   83 | int n, a, b, c;
      |              ^
a.cc:14:14: note: 'int c' previously declared here
   14 | int n, a, b, c;
      |              ^
a.cc:84:13: error: redefinition of 'std::vector<int> l'
   84 | vector<int> l;
      |             ^
a.cc:15:13: note: 'std::vector<int> l' previously declared here
   15 | vector<int> l;
      |             ^
a.cc:86:5: error: redefinition of 'int inf'
   86 | int inf = 1e9;
      |     ^~~
a.cc:17:5: note: 'int inf' previously defined here
   17 | int inf = 1e9;
      |     ^~~
a.cc:88:5: error: redefinition of 'int dfs(int, int, int, int, const std::vector<int>&)'
   88 | int dfs(int v, int aa, int bb, int cc, const vector<int>& l)
      |     ^~~
a.cc:19:5: note: 'int dfs(int, int, int, int, const std::vector<int>&)' previously defined here
   19 | int dfs(int v, int aa, int bb, int cc, const vector<int>& l)
      |     ^~~
a.cc:122:5: error: redefinition of 'int main()'
  122 | int main() {
      |     ^~~~
a.cc:53:5: note: 'int main()' previously defined here
   53 | int main() {
      |     ^~~~