#include using namespace std; using lint =long long; #define rep(i,n) for(lint i=0;i #include #include #include templateusing pbds=__gnu_pbds::tree,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>; templateusing pbds_map=__gnu_pbds::tree,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>; templateusing hash_map=__gnu_pbds::gp_hash_table; templateusing pqueue =__gnu_pbds::priority_queue,__gnu_pbds::rc_binomial_heap_tag>; int main(){ lint n,k,l,p; cin>>n>>k>>l>>p; vector a(n),b(n); rep(i,n)cin>>a[i]>>b[i]; vector>>s; vector>>t; s.resize(n); t.resize(n); rep(i,1<<(n/2)){ lint c=0,v=0; rep(j,n/2){ if(i>>j&1){ c+=a[j]; v+=b[j]; } } s[__builtin_popcountll(i)].emplace_back(c,v); } rep(i,1<<(n-n/2)){ lint c=0,v=0; rep(j,n-n/2){ if(i>>j&1){ c+=a[j+n/2]; v+=b[j+n/2]; } } t[__builtin_popcountll(i)].emplace_back(c,v); } rep(i,n)sort(all(s[i])); rep(i,n)sort(all(t[i])); rep(i,n)reverse(all(t[i])); lint ans=0; rep(i,k+1){ rep(j,k-i+1){ lint now=0; pbds>r; for(auto [c,v]:t[j]){ // cerr<