fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define vll vector<long long>
  5. #define MAXK 1000000
  6. #define mapll map<long long,long long>
  7. ll n,q;
  8. ll a[1000005];
  9. ll pre[1000005];
  10. ll tknp(ll x){
  11. ll l=1,r=n;
  12. ll ans=-1;
  13. while(l<=r){
  14. ll mid=(l+r)/2;
  15. if(a[mid]>=x){
  16. ans=mid;
  17. r=mid-1;
  18. }else{
  19. l=mid+1;
  20. }
  21. }
  22. return ans;
  23. }
  24. int main(){
  25. ios::sync_with_stdio(false);
  26. cin.tie(nullptr);
  27. cout.tie(nullptr);
  28. freopen("STEM.inp","r",stdin);
  29. freopen("STEM.out","w",stdout);
  30. cin>>n;
  31. for(ll i=1;i<=n;i++){
  32. cin>>a[i];
  33. }
  34. sort(a+1,a+1+n);
  35. for(ll i=1;i<=n;i++){
  36. pre[i]=pre[i-1]+a[i];
  37. }
  38. cin>>q;
  39. while(q--){
  40. ll x;
  41. cin>>x;
  42. ll k=tknp(x);
  43. if(k==-1){
  44. cout<<0<<"\n";
  45. continue;
  46. }
  47. cout<<pre[n]-pre[k-1]<<"\n";
  48. }
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty