Language: C++

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

int main()
{
	int total, x, tmp;
	cin >> total >> x;
	vector<int> number(total);
	for (int i = 0; i < total; i++) {
		cin >> number[i];
	}
	sort(number.begin(), number.end());
	/*for (int i = 0; i < total; ++i) {
		for (int j = i + 1; j < total; ++j) {
			if (number[i] > number[j]) {
				tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
		}
	}*/

	int counter = 0;
	for (int i = 0; i < total; i++) {
		if (x - number[i] >= 0) {
			counter++;
			if (x - number > 0 && i == total - 1) {
				counter--
			}
			else if (x - number == 0 && i = total - 1{
				break;
			}
			else{
				x = x - number[i];
		}
	}
		else if (x - number[i] < 0) {
		counter = counter;
			if (counter == 0) {
				counter = 0;
					
			}
		break;
		}
}

cout << counter << endl;
return 0;


}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:31: error: no match for 'operator-' (operand types are 'int' and 'std::vector<int>')
   29 |                         if (x - number > 0 && i == total - 1) {
      |                             ~ ^ ~~~~~~
      |                             |   |
      |                             int std::vector<int>
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:29:33: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   29 |                         if (x - number > 0 && i == total - 1) {
      |                                 ^~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:29:33: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   29 |                         if (x - number > 0 && i == total - 1) {
      |                                 ^~~~~~
a.cc:30:42: error: expected ';' before '}' token
   30 |                                 counter--
      |                                          ^
      |                                          ;
   31 |                         }
      |                         ~                 
a.cc:32:36: error: no match for 'operator-' (operand types are 'int' and 'std::vector<int>')
   32 |                         else if (x - number == 0 && i = total - 1{
      |                                  ~ ^ ~~~~~~
      |                                  |   |
      |                                  int std::vector<int>
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:32:38: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   32 |                         else if (x - number == 0 && i = total - 1{
      |                                      ^~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:32:38: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   32 |                         else if (x - number == 0 && i = total - 1{
      |                                      ^~~~~~
a.cc:32:66: error: expected ')' before '{' token
   32 |                         else if (x - number == 0 && i = total - 1{
      |                                 ~                                ^
      |                                                                  )
a.cc:38:9: error: expected primary-expression before '}' token
   38 |         }
      |         ^