This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
ll n,k,ans=0;
pair<ll,ll> a[50];
vector < pair<ll, ll> > data[2];
void bt1(ll start, ll end,ll val,ll high){
if(start==end+1)
{
data[0].pb(mp(high,val));
return ;
}
if(a[start].fi>=high)
{
val+=a[start].se;
bt1(start+1,end,val,a[start].fi);
val-=a[start].se;
bt1(start+1,end,val,high);
}
else
bt1(start+1,end,val,high);
}
void bt2(ll start, ll end,ll val,ll high){
if(start==end+1)
{
data[1].pb(mp(high,val));
return ;
}
if(a[end].fi<=high)
{
val+=a[end].se;
bt2(start,end-1,val,a[end].fi);
val-=a[end].se;
bt2(start,end-1,val,high);
}
else
bt2(start,end-1,val,high);
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i].fi>>a[i].se;
bt1(1,n/2,0,0);
bt2(n/2+1,n,0,1000000009);
sort(data[1].begin(),data[1].end());
for(int i=0;i<data[0].size();i++)
{
ll pos=lower_bound(data[1].begin(),data[1].end(),mp(data[0][i].fi,0LL))-data[1].begin();
for(int j=pos;j<data[1].size();j++)
if(data[0][i].se+data[1][j].se>=k)
ans++;
}
cout<<ans;
}
Compilation message (stderr)
san.cpp: In function 'int main()':
san.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<data[0].size();i++)
^
san.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=pos;j<data[1].size();j++)
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |