Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,i,mx=INT_MIN,mn=INT_MAX,sum=0,j,a;
- cin>>n;
- int p[n],q;
- for(i=0;i<n;i++)
- {
- cin>>p[i];
- mx=max(mx,p[i]);
- mn=min(mn,p[i]);
- }
- int l=0,r=i-1,len=i-1,num,pw;
- cin>>q;
- int m=(l+r)/2;
- for(i=0;i<q;i++)
- {
- cin>>a;
- l=0;r=len;sum=0;
- if(a>mx)
- {
- for(j=0;j<len+1;j++)
- sum=sum+p[j];
- cout<<len+1<<" "<<sum<<endl;
- }
- else if(a<mn)
- cout<<"0 0"<<endl;
- else
- {
- while(l<=r)
- {
- if(p[m]==a)
- {
- l=m+1;
- break;
- }
- else
- {
- if(a>p[m])
- {
- l=m+1;
- }
- else if(a<p[m])
- {
- r=m-1;
- }
- }
- m=(l+r)/2;
- }
- for(j=0;j<l;j++)
- {
- sum=sum+p[j];
- }
- cout<<l<<" "<<sum<<endl;
- }
- }
- }
Add Comment
Please, Sign In to add comment