#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 45;
ll n, k, sol;
ll h[MAXN], g[MAXN];
vector <ll> sazmi;
vector <ll> v[MAXN];
int get_id(ll x){
return lower_bound(sazmi.begin(), sazmi.end(), x) - sazmi.begin();
}
void brut(int lo, int hi){
REP(i, 1 << (hi - lo + 1)){
ll sum = 0, last = 0;
REP(j, hi + 1){
if(i & (1 << j)){
if(h[j] >= last){
last = h[j];
sum += g[j];
}
else{
last = -1;
break;
}
}
}
if(last != -1)
v[last].pb(sum);
}
}
vector <ll> sazetko;
void solve(int x){
REP(i, x)
sort(v[h[i]].begin(), v[h[i]].end());
REP(i, 1 << x){
ll sum = 0, first = 50, last = 0;
REP(j, n / 2){
if(i & (1 << j)){
int idx = j + x;
if(h[idx] >= last){
if(first == 50) first = h[idx];
last = h[idx];
sum += g[idx];
}
else{
last = -1;
break;
}
}
}
if(last != -1){
for(auto it : sazetko){
if(it <= first){
if(sum >= k){
sol += sz(v[it]);
}
else{
ll threshold = k - sum;
sol += sz(v[it]) - (lower_bound(v[it].begin(), v[it].end(), threshold) - v[it].begin());
}
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
REP(i, n){
cin >> h[i] >> g[i];
sazmi.pb(h[i]);
}
sort(sazmi.begin(), sazmi.end());
sazmi.erase(unique(sazmi.begin(), sazmi.end()), sazmi.end());
REP(i, n){
h[i] = get_id(h[i]) + 1;
if(i <= (n - 1) / 2) sazetko.pb(h[i]);
}
sazetko.pb(0);
sort(sazetko.begin(), sazetko.end());
sazetko.erase(unique(sazetko.begin(), sazetko.end()), sazetko.end());
int mid = (n - 1) / 2;
brut(0, mid);
solve(mid + 1);
cout << sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
472 KB |
Output is correct |
2 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
1080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1080 KB |
Output is correct |
2 |
Incorrect |
31 ms |
1080 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
228 ms |
5756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |