This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3xaMC2q ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
//e
signed main(){
_3xaMC2q;
int n,k;
cin>>n>>k;
vec(pii) a(n);
rep(i,n){
cin>>a[i].fi>>a[i].se;
}
int res=0;
vec(vi) rbts(n);
int si=(n+1)/2;
rep(msk,(1<<(n-si))){
int sun=0,_lst=-1,_fst=-1;
bool pok=1;
rng(i,si,n){
if(msk>>(i-si)&1){
if(a[i].fi<_lst){
pok=0;
break;
}
sun+=a[i].se;
_lst=a[i].fi;
if(_fst==-1)_fst=i;
}
}
if(!pok or _fst==-1) continue;
if(sun>=k){
res+=1;
}
rbts[_fst].pb(sun);
}
rep(i,n){
sort(rbts[i].begin(),rbts[i].end());
}
rep(msk,(1<<si)){
int sun=0,_lst=-1;
bool pok=1;
rep(i,si){
if(msk>>i&1){
if(a[i].fi<_lst){
pok=0;
break;
}
sun+=a[i].se;
_lst=a[i].fi;
}
}
if(!pok or _lst==-1) continue;
if(sun>=k){
res+=1;
}
rng(i,si,n){
if(_lst<=a[i].fi){
int j=(int)(lower_bound(rbts[i].begin(),rbts[i].end(),k-sun)-rbts[i].begin());
// print(msk,_lst);
res+=sz(rbts[i])-j;
}
}
}
print(res);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |