#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
void solve() {
int n;
i64 k;
cin >> n >> k;
vector <int> h(n), g(n);
for(int i = 0; i < n; i++) {
cin >> h[i] >> g[i];
}
vector <int> idxs[n + 2];
int half = n / 2;
i64 ans = 0;
for(int mask = 1; mask < (1 << half); mask++) {
int last = 0, lst = -1;
i64 sum = 0;
bool ok = true;
for(int i = 0; i < half; i++) {
if(mask & (1 << i)) {
if(h[i] < last) {
ok = false;
break;
}
last = h[i];
sum += g[i];
lst = i;
}
}
if(ok) {
idxs[lst].emplace_back(sum);
ans += (sum >= k);
}
}
for(int mask = 1; mask < (1 << (n - half)); mask++) {
int last = 0, fir = -1;
i64 sum = 0;
bool ok = true;
for(int i = 0; i < (n - half); i++) {
if(mask & (1 << i)) {
if(h[i + half] < last) {
ok = false;
break;
}
last = h[i + half];
sum += g[i + half];
if(fir == -1) {
fir = half + i;
}
}
}
if(ok) {
idxs[fir].emplace_back(sum);
ans += (sum >= k);
}
}
for(int i = 0; i < n; i++) {
sort(idxs[i].begin(), idxs[i].end());
/*
cerr << i << ": ";
for(int &j : idxs[i]) {
cerr << j << " ";
}
cerr << "\n";
*/
}
for(int i = 0; i < half; i++) {
for(int &j : idxs[i]) {
for(int l = half; l < n; l++) {
if(h[i] < h[l]) {
auto it = lower_bound(idxs[l].begin(), idxs[l].end(), k - j);
ans += idxs[l].end() - it;
}
}
}
}
cout << ans;
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
984 KB |
Output is correct |
2 |
Incorrect |
17 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
243 ms |
3524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |