Language: C++

using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool dp[2016][10010];
string d2[2][10010];
string s[2016];
int main(){
	int n,k;
	memset(dp,false,sizeof(dp));dp[0][0]=true;
	cin>>n>>k;
	rep(i,n) cin>>s[i];
	rep(i,n) rep(j,k+1){
		if(!dp[i][j]) continue;
		if(j+s[i].size()<=k) dp[i+1][j+s[i].size()]=true;
		dp[i+1][j]=true;
	}
	rep(i,10005) d2[0][i]=d2[1][i]="{";d2[n%2][0]="";
	for(int i=n-1;i>=0;i--){
		int now=i%2,ne=1-now;
		rep(j,k+1) d2[now][j]="{";
		rep(j,k+1){
			if(dp[i][k-j] && d2[ne][j]!="{"){
				d2[now][j]=d2[ne][j];
			}
		}
		rep(j,k+1){
			if(j+s[i].size()<=k && dp[i][k-j-s[i].size()] && d2[ne][j]!="{")
			d2[now][j+s[i].size()]=min(d2[now][j+s[i].size()],s[i]+d2[ne][j]);
		}
	}
	cout<<d2[0][k]<<endl;
	return 0;
}

Compiler output:
a.cc:5:9: error: 'complex' does not name a type
    5 | typedef complex<double> P;
      |         ^~~~~~~
a.cc:9:9: error: 'pair' does not name a type
    9 | typedef pair<int,int> pint;
      |         ^~~~
a.cc:15:1: error: 'string' does not name a type
   15 | string d2[2][10010];
      | ^~~~~~
a.cc:16:1: error: 'string' does not name a type
   16 | string s[2016];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:19:9: error: 'memset' was not declared in this scope
   19 |         memset(dp,false,sizeof(dp));dp[0][0]=true;
      |         ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | using namespace std;
a.cc:20:9: error: 'cin' was not declared in this scope
   20 |         cin>>n>>k;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:21:23: error: 's' was not declared in this scope
   21 |         rep(i,n) cin>>s[i];
      |                       ^
a.cc:24:22: error: 's' was not declared in this scope
   24 |                 if(j+s[i].size()<=k) dp[i+1][j+s[i].size()]=true;
      |                      ^
a.cc:27:22: error: 'd2' was not declared in this scope; did you mean 'dp'?
   27 |         rep(i,10005) d2[0][i]=d2[1][i]="{";d2[n%2][0]="";
      |                      ^~
      |                      dp
a.cc:27:44: error: 'd2' was not declared in this scope; did you mean 'dp'?
   27 |         rep(i,10005) d2[0][i]=d2[1][i]="{";d2[n%2][0]="";
      |                                            ^~
      |                                            dp
a.cc:37:30: error: 's' was not declared in this scope
   37 |                         if(j+s[i].size()<=k && dp[i][k-j-s[i].size()] && d2[ne][j]!="{")
      |                              ^
a.cc:38:48: error: 'min' was not declared in this scope; did you mean 'main'?
   38 |                         d2[now][j+s[i].size()]=min(d2[now][j+s[i].size()],s[i]+d2[ne][j]);
      |                                                ^~~
      |                                                main
a.cc:41:9: error: 'cout' was not declared in this scope
   41 |         cout<<d2[0][k]<<endl;
      |         ^~~~
a.cc:41:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:41:25: error: 'endl' was not declared in this scope
   41 |         cout<<d2[0][k]<<endl;
      |                         ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;