Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
   
  
   
int main(){
   
    int n; 
    int r[1000],w[1000];
    int sum_r=0,sum_w=0,idx=0;
	
    while(scanf("%d",&n),n){
         
        sum_r=sum_w=idx=0;
        for(int i=0;i<n;i++){
            scanf("%d %d",&r[i],&w[i]);
            sum_r+=r[i];
            sum_w+=w[i];
            if(r[idx]<r[i]) idx=i;
        }
  
        int r0=r[idx],r=sum_r-r0;
        w[idx]=0;
 
        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
  
            int res=2*r0;
            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));
  
			bool cur[1000]={};
            cur[0]=true;
            for(int i=0;i<n;i++){
				bool next[1001]={};
                for(int j=0;j<1000;j++){
                    if(cur[j]){
                        next[j]=true; 
                        if(j+w[i]<1000)
                            next[j+w[i]]=true; 
                    }
                }
				swap(cur,next);
            }
  
            int opt=r0-r;
            while(!cur[opt]) opt--;
  
            res+=sum_w-opt;
            printf("%d\n",res);
  
  
  
        }
          
          
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:37: error: no matching function for call to 'swap(bool [1000], bool [1001])'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'bool [1000]' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   deduced conflicting types for parameter '_Tp' ('bool [1000]' and 'bool [1001]')
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   deduced conflicting values for non-type parameter '_Nm' ('1000' and '1001')
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 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:
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::pair<_T1, _T2>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::pair<_T1, _T2>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:4039:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(__cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4039 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/basic_string.h:4039:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2805:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)'
 2805 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/14/tuple:2805:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::tuple<_UTypes ...>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
/usr/include/c++/14/tuple:2823:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)' (deleted)
 2823 |     swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
      |     ^~~~
/usr/include/c++/14/tuple:2823:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::tuple<_UTypes ...>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:2122:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(vector<_Tp, _Alloc>&, vector<_Tp, _Alloc>&)'
 2122 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_vector.h:2122:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::vector<_Tp, _Alloc>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/functional:59,
                 from a.cc:9:
/usr/include/c++/14/bits/std_function.h:782:5: note: candidate: 'template<class _Res, class ... _Args> void std::swap(function<_Res(_ArgTypes ...)>&, function<_Res(_ArgTypes ...)>&)'
  782 |     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
      |     ^~~~
/usr/include/c++/14/bits/std_function.h:782:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::function<_Res(_ArgTypes ...)>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63:
/usr/include/c++/14/bits/unordered_map.h:2130:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2130 |     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/14/bits/unordered_map.h:2130:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:2137:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2137 |     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/14/bits/unordered_map.h:2137:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/functional:65:
/usr/include/c++/14/array:377:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value)> std::swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&)'
  377 |     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
      |     ^~~~
/usr/include/c++/14/array:377:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::array<_Tp, _Nm>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
/usr/include/c++/14/array:384:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)(! typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value))> std::swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&)' (deleted)
  384 |     swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) = delete;
      |     ^~~~
/usr/include/c++/14/array:384:5: note:   template argument deduction/substitution failed:
a.cc:56:37: note:   mismatched types 'std::array<_Tp, _Nm>' and 'bool [1000]'
   56 |                                 swap(cur,next);
      |                                 ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/set:62,
                 from a.cc:10:
/usr/include/c++/14/bits/stl_tree.h:1675:5: note: candidate: 'template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> void std::swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)'
 1675 |     swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/14/bits/stl_tree.h:1675:5: note