#include #include int cmp_ll (const void *ap, const void *bp) { long long a = *(long long *)ap; long long b = *(long long *)bp; if (a < b) { return -1; } if (a > b) { return 1; } return 0; } void set_segt (int *t, int idx, int val, int size) { idx += size-1; t[idx] = val; while (idx > 0) { idx = (idx-1)/2; t[idx] = t[2*idx+1]+t[2*idx+2]; } return; } int sum_segt_rec (int *t, int a, int b, int k, int l, int r) { int ans = 0; if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return t[k]; } ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2); ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r); return ans; } int sum_segt (int *t, int a, int b, int size) { return sum_segt_rec(t, a, b, 0, 0, size); } int main () { int n = 0; int k = 0; long long l = 0LL; long long p = 0LL; long long a[34] = {}; long long b[34] = {}; int res = 0; long long ans = 0LL; long long sumabc1[1000000][3] = {}; long long sumabc2[1000000][3] = {}; long long sumb_sort[1000000][2] = {}; int sumb_map[1000000] = {}; int size = 1; int segt[18][1000000] = {}; int n1 = 0; int n2 = 0; int idx = 0; res = scanf("%d", &n); res = scanf("%d", &k); res = scanf("%lld", &l); res = scanf("%lld", &p); for (int i = 0; i < n; i++) { res = scanf("%lld", a+i); res = scanf("%lld", b+i); } if (n <= 1) { if (a[0] <= l && b[0] >= p) { ans = 1LL; } else { ans = 0LL; } printf("%lld\n", ans); return 0; } n2 = n/2; n1 = n-n2; for (int i = 0; i < (1< 0) { sumabc1[i][0] += a[j]; sumabc1[i][1] += b[j]; sumabc1[i][2] += 1LL; } } } for (int i = 0; i < (1< 0) { sumabc2[i][0] += a[n1+j]; sumabc2[i][1] += b[n1+j]; sumabc2[i][2] += 1LL; } } } qsort(sumabc1, (1<= 0; i--) { int r[2] = { -1, (1< 1) { int nxt = (r[0]+r[1])/2; if (sumb_sort[nxt][0]+sumabc1[i][1] < p) { r[0] = nxt; } else { r[1] = nxt; } } for (int j = 0; j <= k-((int)(sumabc1[i][2])); j++) { ans += (long long) sum_segt(segt[j], r[1], (1<