func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   inline T smax(T &a, const S &b) {     return a < b ? a = b : a;   }   int n, s, m, k, a[int(1500 + 20)], l[int(1500 + 20)], r[int(1500 + 20)],       id[int(1500 + 20)];   int psum[int(1500 + 20)], dp[int(1500 + 20)][int(1500 + 20)],       pos[int(1500 + 20)];   inline bool check(int val) {     for (int i = 1; i <= n; i++) {       psum[i] = psum[i - 1] + ((a[i] <= val) ? 1 : 0);       for (int j = 1; j <= m; j++) {         dp[i][j] = dp[i - 1][j];         if (!~pos[i]) continue;         int L = l[pos[i]];         smax(dp[i][j], dp[L - 1][j - 1] + psum[i] - psum[L - 1]);         L = r[id[pos[i]]];         smax(dp[i][j], dp[L][j - 1] + psum[i] - psum[L]);       }     }     return dp[n][m] >= k;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.tie(0);     cin >> n >> s >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 0; i < s; i++) cin >> l[i] >> r[i];     memset(id, -1, sizeof(id));     memset(pos, -1, sizeof(pos));     for (int i = 0; i < s; i++) {       if (!~pos[r[i]] || l[pos[r[i]]] > l[i]) pos[r[i]] = i;       for (int j = 0; j < s; j++)         if (r[j] <= r[i] && r[j] >= l[i])           if (!~id[i] || l[id[i]] > l[j]) id[i] = j;     }     int lo = 0, hi = 1e9 + 2;     while (lo != hi - 1) {       int mid = (long long)lo + hi >> 1;       if (check(mid))         hi = mid;       else         lo = mid;     }     if (!check(hi)) hi = -1;     cout << hi << endl;     return 0;   }   