#include <bits/stdc++.h>
using namespace std;
vector <long long> v2[40];
vector <pair<long long ,int> > v1;
int n;
long long k,h[50],c[50];
void bt (int pos,int x,long long first,int last,long long sum)
{
if (pos==x)
{
if (x!=n+1)
v1.push_back({sum,last});
else
{
for (int i=0;i<=n/2;i++)
if (first>=h[i]) v2[i].push_back(sum);
}
return ;
}
if (h[pos]>=h[last])
bt(pos+1,x,min(first,h[pos]),pos,sum+c[pos]);
bt(pos+1,x,first,last,sum);
}
int main()
{
cin >>n>>k;
for (int i=1;i<=n;i++)
cin >>h[i]>>c[i];
bt(1,n/2+1,1e12,0,0);
bt(n/2+1,n+1,1e12,0,0);
for (int i=0;i<=n/2;i++)
sort(v2[i].begin(),v2[i].end());
long long ans=0;
for (int i=0;i<v1.size();i++)
{
int idx= v1[i].second;
long long sum= v1[i].first;
sum= (k-sum);
int p1= lower_bound(v2[idx].begin(),v2[idx].end(),sum)-v2[idx].begin();
ans+= (v2[idx].size()-p1);
}
cout <<ans;
return 0;
}
Compilation message
san.cpp: In function 'int main()':
san.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v1.size();i++)
~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
560 KB |
Output is correct |
2 |
Correct |
2 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10016 KB |
Output is correct |
2 |
Correct |
6 ms |
10016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
26764 KB |
Output is correct |
2 |
Correct |
12 ms |
26764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1081 ms |
127892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |