#include <bits/stdc++.h>
using namespace std;
const int maxn = 45;
typedef long long ll;
typedef pair<int, int> pii;
int n;
pii num[maxn];
vector<int> v[maxn];
void compress(void)
{
map<int, int> M;
vector<int> cc;
for (int i = 0; i < n; i++)
cc.push_back(num[i].first);
sort(cc.begin(), cc.end());
int ind = 0;
for (auto x: cc)
if (M.find(x) == M.end())
M[x] = ++ind;
for (int i = 0; i < n; i++)
num[i].first = M[num[i].first];
}
int main(void)
{
ios::sync_with_stdio(false); cin.tie(0);
ll k;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> num[i].first >> num[i].second;
compress();
int m = n/2;
ll ans = 0LL;
for (int mask = 1; mask < (1<<m); mask++)
{
int atual = 0;
ll soma = 0LL;
bool ok = 1;
for (int i = 0; i < m; i++)
{
if (!(mask&(1<<i))) continue;
if (num[i].first < atual)
{
ok = 0;
break;
}
soma += (ll) num[i].second;
atual = num[i].first;
}
if (ok)
{
if (soma >= k) ans++;
v[atual].push_back(soma);
}
}
for (int i = 1; i <= n; i++)
sort(v[i].begin(), v[i].end());
int mm = n-m;
for (int mask = 0; mask < (1<<mm); mask++)
{
int atual = 0;
ll soma = 0LL;
bool ok = 1;
for (int i = 0; i < m; i++)
{
if (!(mask&(1<<i))) continue;
i+=m;
if (num[i].first < atual)
{
ok = 0;
break;
}
soma += (ll) num[i].second;
atual = num[i].first;
}
if (ok)
{
if (soma >= k) ans++;
for (int i = 1; i <= atual; i++)
{
if (v[i].back() < k-soma) continue;
vector<int>::iterator it = lower_bound(v[i].begin(), v[i].end(), k-soma);
ans += (ll)((int)(v[i].end()-it));
}
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
708 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
980 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
1364 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
66 ms |
3416 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |