Hackerearth Bishu and Soldiers Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,i,m,a,r;
- vector<int>v;
- cin>>n;
- for(i=0; i<n; i++)
- {
- cin>>a;
- v.push_back(a);
- }
- sort(v.begin(),v.end());
- int s[n+1]={0};
- for(i=1;i<=n;i++)
- {
- s[i]=v[i-1]+s[i-1];
- }
- cin>>m;
- while(m--)
- {
- cin>>r;
- int pos=upper_bound(v.begin(),v.end(),r)-v.begin();
- cout<<pos<<" "<<s[pos]<<endl;
- }
- }
No comments