Codeforces Round #827 (Div. 4) 1742E. Scuza Solution


 Problem Link:  https://codeforces.com/problemset/problem/1742/E

 Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************/
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. #define ll long long
  10. int main()
  11. {
  12. int t;
  13. cin>>t;
  14. while(t--)
  15. {
  16. ll n,q,i,t,mx=0,x;
  17. vector<int>v;
  18. cin>>n>>q;
  19. ll a[n+1];
  20. for(i=1; i<=n; i++)
  21. {
  22. cin>>a[i];
  23. mx=max(mx,a[i]);
  24. v.push_back(mx);
  25. }
  26. a[0]=0;
  27. for(i=2; i<=n; i++)
  28. {
  29. a[i]+=a[i-1];
  30. }
  31. while(q--)
  32. {
  33. cin>>x;
  34. int index;
  35. index=upper_bound(v.begin(),v.end(),x)-v.begin();
  36. cout<<a[index]<<" ";
  37. }
  38. cout<<endl;
  39. }
  40. }

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 &g...

Powered by Blogger.