beats 90% at speed, 42ms, O(nlogn + n + m) 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 
# 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```\nimpl Solution {\n\tpub fn min_operations(mut nums: Vec<i32>, queries: Vec<i32>) -> Vec<i64> {\n\t\tnums.sort_unstable();  // O(nlogn)\n\t\tlet (nl, ql) = (nums.len(), queries.len());\n\t\tlet mut prefix_sums: Vec<i64> = Vec::with_capacity(nl);\n\t\tnums.iter().fold(0i64, |acc, &val| {\n\t\t\tprefix_sums.push(acc + val as i64);\n\t\t\tacc + val as i64\n\t\t}); // O(n)\n\t\tqueries.iter().fold(Vec::<i64>::with_capacity(ql), |mut acc, &q| {\n\t\t\tif let Some(idx) = Self::find_index(&nums, q) {\n\t\t\t\tacc.push(((idx << 1) as i64 + 2 - nl as i64) * q as i64 - 2 * prefix_sums[idx] + prefix_sums[nl-1]);\n\t\t\t\tacc\n\t\t\t} else {\n\t\t\t\tacc.push(prefix_sums[nl-1] - nl as i64 * q as i64);\n\t\t\t\tacc\n\t\t\t}\n\t\t})\n\t}\n\tfn find_index(nums: &Vec<i32>, n: i32) -> Option<usize> {\n\t\tlet mut result: Option<usize> = None;\n\t\tlet mut low: i32 = 0;\n\t\tlet mut high: i32 = nums.len() as i32 - 1;\n\t\twhile low <= high {\n\t\t\tlet mid = low + (high - low) / 2;\n\t\t\tif nums[mid as usize] < n {\n\t\t\t\tresult = Some(mid as usize);\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\tresult\n\t}\n}\n\n```
['Rust']