#include using namespace std; int countPairs(const vector& projectCosts, int target) { // Using an unordered set to keep track of visited numbers unordered_set visited; int count = 0; // Iterate through each number in the list for (int cost : projectCosts) { // Check if there exists a number with the required difference if (visited.count(cost + target)) { count++; } if (visited.count(cost - target)) { count++; } // Add the current number to the visited set visited.insert(cost); } return count; } int main() { vector projectCosts = {1, 3, 5}; int target = 2; int result = countPairs(projectCosts, target); cout << result << endl; // Output should be 2 return 0; }