#include <bits/stdc++.h>
#define int ll
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1280 KB |
Output is correct |
2 |
Correct |
20 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
2296 KB |
Output is correct |
2 |
Correct |
89 ms |
728 KB |
Output is correct |