Language: C++

#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 3010;
inline char get() {
	static char buf[10000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 10000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
char c;
inline void read(int &x) {
	x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}
inline void read(string& s) {
  for (c = get(); c == ' ' || c == '\n'; c = get());
  for (; c != ' ' && c != '\n'; c = get()) s.push_back(c);
}

string s, t;
short dp[N][N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(s); read(t);
  int n = s.size(), m = t.size();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if (s[i-1] == t[j-1]) {
        dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      }
    }
  }
  string ans;
  int ci = n, cj = m;
  while (ci && cj) {
    if (dp[ci-1][cj] == dp[ci][cj]) {
      ci--;
    } else if (dp[ci][cj-1] == dp[ci][cj]) {
      cj--;
    } else {
      //assert(s[ci-1] == t[cj-1] && dp[ci-1][cj-1] + 1 == dp[ci][cj]);
      ans.push_back(s[ci-1]);
      ci--;
      cj--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << nl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:23: error: no matching function for call to 'max(short int&, int)'
   43 |         dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:43:23: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   43 |         dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:43:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   43 |         dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~