Hackerearth Bishu and Soldiers Solution

 Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh  

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,i,m,a,r;
  6. vector<int>v;
  7. cin>>n;
  8. for(i=0; i<n; i++)
  9. {
  10. cin>>a;
  11. v.push_back(a);
  12. }
  13. sort(v.begin(),v.end());
  14. int s[n+1]={0};
  15. for(i=1;i<=n;i++)
  16. {
  17. s[i]=v[i-1]+s[i-1];
  18. }
  19. cin>>m;
  20. while(m--)
  21. {
  22. cin>>r;
  23. int pos=upper_bound(v.begin(),v.end(),r)-v.begin();
  24. cout<<pos<<" "<<s[pos]<<endl;
  25. }
  26. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.