Language: C++

using namespace std;

map<vector<int>, int> m;
vector<vector<int> > mp;

int getMax(vector<int> p, int sum)
{
	int a;
	if (m.find(p) != m.end()){
		return (m[p]);
	}
	
	if (sum < 10){
		return (m[p] = 0);
	}
	
	a = 0;
	for (int i = 0; i < (int)mp.size(); i++){
		vector<int> c = p;
		bool flag;
		flag = true;
		
		for (int j = 1; j < (int)mp[i].size(); j++){
			c[j] -= mp[i][j];
			if (c[j] < 0){
				flag = false;
				break;
			}
		}
		
		if (flag == true){
			a = max(a, 1 + getMax(c, sum - 10));
		}
	}
	
	return (m[p] = a);
}


void make(vector<int> t, int n, int lim)
{
	if (lim == 0 || n == 10){
		if (!lim){
			mp.push_back(t);
			m[t] = 1;
		}
		return;
	}
	
	for (int i = 0; i * n <= lim; i++){
		vector<int> tn = t;
		tn.push_back(i);
		make(tn, n + 1, lim - i * n);
	}
	
	return;
}

int main(void)
{
	int n;
	int ans;
	vector<int> num(10);
	vector<int> t;
	
	t.push_back(0);
	make(t, 1, 10);
	
	while (scanf("%d", &n) && n){
		
		fill(num.begin(), num.end(), 0);
		
		for (int i = 0; i < n; i++){
			int t;
			scanf("%d", &t);
			num[t]++;
		}
		
		ans = 0;
		
		for (int i = 1; i <= 4; i++){
			int m = min(num[i], num[10 - i]);
			ans += m;
			num[i] -= m; num[10 - i] -= m;
		}
		ans += num[5] / 2; num[5] %= 2;
		
		int s = 0;
		for (int i = 1; i <= 9; i++){
			s += i * num[i];
		}
		
		printf("%d\n", ans + getMax(num, s));
	}
	
	return (0);
}

Compiler output:
a.cc:3:1: error: 'map' does not name a type
    3 | map<vector<int>, int> m;
      | ^~~
a.cc:4:1: error: 'vector' does not name a type
    4 | vector<vector<int> > mp;
      | ^~~~~~
a.cc:6:12: error: 'vector' was not declared in this scope
    6 | int getMax(vector<int> p, int sum)
      |            ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:6:19: error: expected primary-expression before 'int'
    6 | int getMax(vector<int> p, int sum)
      |                   ^~~
a.cc:6:27: error: expected primary-expression before 'int'
    6 | int getMax(vector<int> p, int sum)
      |                           ^~~
a.cc:6:34: error: expression list treated as compound expression in initializer [-fpermissive]
    6 | int getMax(vector<int> p, int sum)
      |                                  ^
a.cc:40:6: error: variable or field 'make' declared void
   40 | void make(vector<int> t, int n, int lim)
      |      ^~~~
a.cc:40:11: error: 'vector' was not declared in this scope
   40 | void make(vector<int> t, int n, int lim)
      |           ^~~~~~
a.cc:40:11: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:40:18: error: expected primary-expression before 'int'
   40 | void make(vector<int> t, int n, int lim)
      |                  ^~~
a.cc:40:26: error: expected primary-expression before 'int'
   40 | void make(vector<int> t, int n, int lim)
      |                          ^~~
a.cc:40:33: error: expected primary-expression before 'int'
   40 | void make(vector<int> t, int n, int lim)
      |                                 ^~~
a.cc: In function 'int main()':
a.cc:63:9: error: 'vector' was not declared in this scope
   63 |         vector<int> num(10);
      |         ^~~~~~
a.cc:63:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:63:16: error: expected primary-expression before 'int'
   63 |         vector<int> num(10);
      |                ^~~
a.cc:64:16: error: expected primary-expression before 'int'
   64 |         vector<int> t;
      |                ^~~
a.cc:66:9: error: 't' was not declared in this scope
   66 |         t.push_back(0);
      |         ^
a.cc:67:9: error: 'make' was not declared in this scope
   67 |         make(t, 1, 10);
      |         ^~~~
a.cc:69:16: error: 'scanf' was not declared in this scope
   69 |         while (scanf("%d", &n) && n){
      |                ^~~~~
a.cc:71:22: error: 'num' was not declared in this scope; did you mean 'enum'?
   71 |                 fill(num.begin(), num.end(), 0);
      |                      ^~~
      |                      enum
a.cc:71:17: error: 'fill' was not declared in this scope
   71 |                 fill(num.begin(), num.end(), 0);
      |                 ^~~~
a.cc:82:33: error: 'min' was not declared in this scope; did you mean 'main'?
   82 |                         int m = min(num[i], num[10 - i]);
      |                                 ^~~
      |                                 main
a.cc:93:44: error: 'getMax' cannot be used as a function
   93 |                 printf("%d\n", ans + getMax(num, s));
      |                                      ~~~~~~^~~~~~~~
a.cc:93:17: error: 'printf' was not declared in this scope
   93 |                 printf("%d\n", ans + getMax(num, s));
      |                 ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | using namespace std;