c++ code
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        long long  n=nums.size();\n        sort(nums.begin(),nums.end());\n        vector<long long > pre(n+1,0);\n        for(int i=0;i<n;i++){\n            pre[i+1]=pre[i]+nums[i];\n        }\n       \n        vector<long long > ans;\n        for(auto it:queries){\n            long long l=lower_bound(nums.begin(),nums.end(),it)-nums.begin();\n            long long up=upper_bound(nums.begin(),nums.end(),it)-nums.begin();\n            long long val=it*l-(pre[l]-pre[0]);\n            if(up!=n){\n                val+=(pre[n]-pre[up])-it*(n-up);\n            }\n            ans.push_back(val);\n        }\n        return ans;\n    }\n};\n```
['C++']