Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#define N 105000
#define INFINITY 2000000000
using namespace std;
int dp[N][N],data[N];
vector<int> data2;
int DP(int);
int DP2(int);
int main(){
  int i,out,out2,n;
  data2.push_back(0);
  for(i=1;i<N;i++){
    data[i]=i*(i+1)*(i+2)/6;
    if(data[i]%2==1){
      data2.push_back(data[i]);
    }
  }
  while(1){
    cin >> n;
    if(n==0) break;
    out=DP(n);
    out2=DP2(n);
    cout << out << ' ' << out2 << endl;
  }
  return 0;
}
int DP(int n){
  int i,j,minret,s;
  for(i=1;i<N;i++){
    if(data[i]>n){
      s=i-1;
      break;
    }
  }
  for(i=0;i<=n;i++) dp[0][i]=INFINITY;
  for(i=0;i<=s;i++) dp[i][0]=0;
  for(i=1;i<=s;i++){
    for(j=1;j<=n;j++){
      if(j>=data[i]) dp[i][j]=min(dp[i-1][j],dp[i][j-data[i]]+1);
      else dp[i][j]=dp[i-1][j];
    }
  }
  minret=INFINITY;
  for(i=1;i<=s;i++) minret=min(minret,dp[i][n]);
  return minret;
}
int DP2(int n){
  int i,j,minret,s,len;
  len=data2.size();
  for(i=1;i<len;i++){
    if(data2[i]>n){
      s=i-1;
      break;
    }
  }
  for(i=0;i<=n;i++) dp[0][i]=INFINITY;
  for(i=0;i<=s;i++) dp[i][0]=0;
  for(i=1;i<=s;i++){
    for(j=1;j<=n;j++){
      if(j>=data2[i]) dp[i][j]=min(dp[i-1][j],dp[i][j-data2[i]]+1);
      else dp[i][j]=dp[i-1][j];
    }
  }
  minret=INFINITY;
  for(i=1;i<=s;i++) minret=min(minret,dp[i][n]);
  return minret;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: reference to 'data' is ambiguous
   15 |     data[i]=i*(i+1)*(i+2)/6;
      |     ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:14: note:                 'int data [105000]'
    7 | int dp[N][N],data[N];
      |              ^~~~
a.cc:16:8: error: reference to 'data' is ambiguous
   16 |     if(data[i]%2==1){
      |        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:14: note:                 'int data [105000]'
    7 | int dp[N][N],data[N];
      |              ^~~~
a.cc:17:23: error: reference to 'data' is ambiguous
   17 |       data2.push_back(data[i]);
      |                       ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:14: note:                 'int data [105000]'
    7 | int dp[N][N],data[N];
      |              ^~~~
a.cc: In function 'int DP(int)':
a.cc:32:8: error: reference to 'data' is ambiguous
   32 |     if(data[i]>n){
      |        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:14: note:                 'int data [105000]'
    7 | int dp[N][N],data[N];
      |              ^~~~
a.cc:41:13: error: reference to 'data' is ambiguous
   41 |       if(j>=data[i]) dp[i][j]=min(dp[i-1][j],dp[i][j-data[i]]+1);
      |             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:14: note:                 'int data [105000]'
    7 | int dp[N][N],data[N];
      |              ^~~~
a.cc:41:54: error: reference to 'data' is ambiguous
   41 |       if(j>=data[i]) dp[i][j]=min(dp[i-1][j],dp[i][j-data[i]]+1);
      |                                                      ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:14: note:                 'int data [105000]'
    7 | int dp[N][N],data[N];
      |              ^~~~