#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define pb push_back
typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 5e5+1;
const int inf = 1e9+1;
void solve() {
int n,k;
cin >> n >> k;
vi h(n+1),g(n+1);
F(i,n) cin >> h[i] >> g[i];
int n1 = n-n/2,n2 = n/2;
int lim = (1<<n2);
vi sm(lim);
ordered_set ss[n2+1];
int ans = 0;
for (int i=1;i<lim;i++) {
int smm = 0;
int prev = 0,first=0;
bool cool = 1;
for (int j=0;j<n2;j++) {
if (i&(1<<j)) {
if (h[n1+j+1] < prev) {
cool = 0;
break;
}
if (!first) first = j+1;
prev = h[n1+j+1];
smm+=g[n1+j+1];
}
}
if (!cool) continue;
if (smm >= k) ans++;
ss[first].insert({smm,i});
}
lim = (1<<n1);
for (int i=1;i<lim;i++) {
int smm = 0,prev = 0;
bool cool = 1;
for (int j=0;j<n1;j++) {
if (i&(1<<j)) {
if (h[j+1] < prev) {
cool = 0;
break;
}
prev = h[j+1];
smm += g[j+1];
}
}
if (!cool) continue;
if (smm >= k) ans++;
for (int j=1;j<=n2;j++) {
if (h[n1+j] >= prev) ans+=(int)ss[j].size()-ss[j].order_of_key({k-smm,0});
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2652 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
10712 KB |
Output is correct |
2 |
Correct |
20 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
346 ms |
21076 KB |
Output is correct |
2 |
Correct |
95 ms |
10964 KB |
Output is correct |