func_code_string: #include <bits/stdc++.h>   using namespace std;   const int n0 = 1503, inf = 1e9;   int n, s, m, k, a[n0], b[n0], p[n0], L[n0];   int dp[2][n0], mx[n0], best[n0];   int num(int pos) {     for (int i = 1; i <= n; i++) {       p[i] = p[i - 1] + (a[i] <= b[pos]);     }     memset(&dp, -0x3f, sizeof(dp));     int res = 0;     for (int i = 1; i <= m; i++) {       dp[(i - 1) & 1][0] = 0;       mx[0] = dp[(i - 1) & 1][0];       for (int j = 1; j <= n; j++) {         mx[j] = max(mx[j - 1], dp[(i - 1) & 1][j]);         if (L[j] != n0) {           if (best[j] != -1)             dp[i & 1][j] = dp[(i - 1) & 1][best[j]] - p[best[j]] + p[j];           dp[i & 1][j] = max(dp[i & 1][j], mx[L[j] - 1] + p[j] - p[L[j] - 1]);           if (i == m) res = max(res, dp[i & 1][j]);         }       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n >> s >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i], L[i] = n0;     sort(b + 1, b + n + 1);     for (int i = 0; i < s; i++) {       int l, r;       cin >> l >> r;       L[r] = min(L[r], l);     }     for (int i = 1; i <= n; i++) {       best[i] = -1;       for (int j = L[i]; j < i; j++) {         if (best[i] == -1 || L[j] < L[best[i]]) best[i] = j;       }     }     int l = 0, r = n + 1;     while (l < r - 1) {       int mid = l + r >> 1;       if (num(mid) >= k)         r = mid;       else         l = mid;     }     if (r == n + 1)       cout << -1;     else       cout << b[r];   }   