Language: C++

#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<map>
/#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
int main(){
   int mt[] = {0, 2, 5, 5, 4, 5, 6, 3 , 7, 6};

   int n,m;
   I2(n,m);
   pair<int,int> ar[m+2];
   for(int i =1;i<=m;i++){
       I(ar[i].x);
       ar[i].y = mt[ar[i].x];
   }
   int DP[n+2];
   SETR(DP);
   DP[0] = 0;
   sort(ar + 1, ar + m+ 1);
   int ans = 0;
   int in = 0;
   for(int i = 1;i<=m;i++){
       for(int j = ar[i].y;j<=n;j++){
           if(DP[j-ar[i].y] !=-1){
               DP[j]= max(DP[j],1 + DP[j-ar[i].y]);
            
           }
       
           if(DP[j] >=ans){
               ans = DP[j];
           }
       }
   }
   for(int j = n;j>=1;j--){
       if(DP[j] == ans){
           in= j;
           break;
       }
   }
   int cnt = 0;
   for(int j = in; j>0;){
       for(int k = m;k>=1;k--){
           if(j-ar[k].y >=0 && DP[j-ar[k].y] == ans-1){
               //cout<<DP[j]<<" "<<DP[j-ar[k].y]<<" "<<endl;
               ans--;
               j = j - ar[k].y;
              cout<<ar[k].x;
              //cout<<j<<endl;
               cnt++;
               break;
           }
       }
   }
   cout<<endl;
    return 0;
}

Compiler output:
a.cc:13:2: error: stray '#' in program
   13 | /#include<bits/stdc++.h>
      |  ^
a.cc:13:1: error: expected unqualified-id before '/' token
   13 | /#include<bits/stdc++.h>
      | ^
a.cc:89:9: error: 'pair' does not name a type; did you mean 'pi'?
   89 | typedef pair<int,int >P;
      |         ^~~~
      |         pi
a.cc: In function 'int main()':
a.cc:97:4: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   97 |    pair<int,int> ar[m+2];
      |    ^~~~
      |    std::pair
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:3013:12: note: 'std::pair' declared here
 3013 |     struct pair;
      |            ^~~~
a.cc:97:9: error: expected primary-expression before 'int'
   97 |    pair<int,int> ar[m+2];
      |         ^~~
a.cc:99:10: error: 'ar' was not declared in this scope; did you mean 'fr'?
   99 |        I(ar[i].x);
      |          ^~
a.cc:16:26: note: in definition of macro 'I'
   16 | #define I(a) scanf("%d",&a)
      |                          ^
a.cc:36:17: error: 'memset' was not declared in this scope
   36 | #define SETR(a) memset(a,-1,sizeof a)
      |                 ^~~~~~
a.cc:103:4: note: in expansion of macro 'SETR'
  103 |    SETR(DP);
      |    ^~~~
a.cc:13:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   12 | #include<map>
  +++ |+#include <cstring>
   13 | /#include<bits/stdc++.h>
a.cc:105:9: error: 'ar' was not declared in this scope; did you mean 'fr'?
  105 |    sort(ar + 1, ar + m+ 1);
      |         ^~
      |         fr
a.cc:105:4: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
  105 |    sort(ar + 1, ar + m+ 1);
      |    ^~~~
      |    std::sort
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:2:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
a.cc:111:23: error: 'max' was not declared in this scope; did you mean 'std::max'?
  111 |                DP[j]= max(DP[j],1 + DP[j-ar[i].y]);
      |                       ^~~
      |                       std::max
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:133:15: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
  133 |               cout<<ar[k].x;
      |               ^~~~
      |               std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:140:4: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
  140 |    cout<<endl;
      |    ^~~~
      |    std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:140:10: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
  140 |    cout<<endl;
      |          ^~~~
      |          std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~