1 | //https://www.xinyoudui.com/ac/contest/747005D6B0006AA046984F6/problem/7253 11pts RE+WA |
2 | #include<bits/stdc++.h> |
3 | using namespace std; |
4 | const int M=15; |
5 | const int N=1e4+10; |
6 | const int N2=510; |
7 | struct node |
8 | { |
9 | int v; |
10 | int c; |
11 | }; |
12 | node a[M]; |
13 | int dp[N]; |
14 | int n,m; |
15 | int b[N2]; |
16 | node c[N2]; |
17 | bool cmp(node a,node b) |
18 | { |
19 | if(a.v!=b.v) |
20 | { |
21 | return a.v<b.v; |
22 | } |
23 | return a.c>b.c; |
24 | } |
25 | bool cmp2(node a,node b) |
26 | { |
27 | return a.c>b.c; |
28 | } |
29 | // void dfs(int x,int ans) |
30 | // { |
31 | // if(x>dp[n]) |
32 | // { |
33 | // if(ans==n) |
34 | // { |
35 | // for(int i=1;i<=dp[n];i++) |
36 | // { |
37 | // if(b[i]==0) |
38 | // { |
39 | // return; |
40 | // } |
41 | // } |
42 | // for(int i=1;i<=dp[n];i++) |
43 | // { |
44 | // if(b[i]>c[i]) |
45 | // { |
46 | // for(int j=1;j<=dp[n];j++) |
47 | // { |
48 | // c[i]=b[i]; |
49 | // } |
50 | // return; |
51 | // } |
52 | // else if(b[i]<c[i]) |
53 | // { |
54 | // return; |
55 | // } |
56 | // } |
57 | // } |
58 | // return; |
59 | // } |
60 | // for(int i=1;i<=m;i++) |
61 | // { |
62 | // b[x]=a[i].c; |
63 | // dfs(x+1,ans+a[i].v); |
64 | // b[x]=0; |
65 | // } |
66 | // } |
67 | int main() |
68 | { |
69 | cin>>n>>m; |
70 | for(int i=1;i<=m;i++) |
71 | { |
72 | cin>>a[i].c; |
73 | if(a[i].c==1) |
74 | { |
75 | a[i].v=2; |
76 | } |
77 | else if(a[i].c==2||a[i].c==3||a[i].c==5) |
78 | { |
79 | a[i].v=5; |
80 | } |
81 | else if(a[i].c==4) |
82 | { |
83 | a[i].v=4; |
84 | } |
85 | else if(a[i].c==6||a[i].c==9) |
86 | { |
87 | a[i].v=6; |
88 | } |
89 | else if(a[i].c==7) |
90 | { |
91 | a[i].v=3; |
92 | } |
93 | else |
94 | { |
95 | a[i].v=7; |
96 | } |
97 | } |
98 | sort(a+1,a+1+m,cmp); |
99 | // for(int i=1;i<=m;i++) |
100 | // { |
101 | // cout<<a[i].c<<' '<<a[i].v<<endl; |
102 | // } |
103 | for(int i=1;i<=m;i++) |
104 | { |
105 | for(int j=a[i].v;j<=n;j++) |
106 | { |
107 | int d=dp[j]; |
108 | dp[j]=max(dp[j],dp[j-a[i].v]+1); |
109 | if(d!=dp[j]) |
110 | { |
111 | c[dp[j]].c=a[i].c; |
112 | c[dp[j]].v=a[i].v; |
113 | } |
114 | } |
115 | } |
116 | // cout<<dp[n]; |
117 | // dfs(1,0); |
118 | sort(c+1,c+1+n,cmp2); |
119 | int V=0; |
120 | int d=0; |
121 | while(V!=n) |
122 | { |
123 | V=0; |
124 | for(int i=1;i<=dp[n];i++) |
125 | { |
126 | V+=c[i].v; |
127 | } |
128 | if(V!=n) |
129 | { |
130 | V-=c[dp[n]-d].v; |
131 | for(int i=1;i<=m;i++) |
132 | { |
133 | if(n-V==a[i].v) |
134 | { |
135 | c[dp[n]-d].v=a[i].v; |
136 | c[dp[n]-d].c=a[i].c; |
137 | break; |
138 | } |
139 | } |
140 | } |
141 | d++; |
142 | } |
143 | for(int i=1;i<=dp[n];i++) |
144 | { |
145 | cout<<c[i].c; |
146 | } |
147 | return 0; |
148 | } |