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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.