(Problem: edit: CSES - Sum of Two Values)
I coded this problem using an unordered_map, and it time limit exceeded. However, I switched to an ordered map and it was accepted. I read the solution and the solution states that using an unordered_map should work as well. Using an unordered_map also visibly runs faster (on large test cases) when I run it in VSCode. Can anyone tell me why an ordered map was accepted while an unordered map wasn’t?
My code:
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n; cin >> n;
int target; cin >> target;
/*unordered_*/map<int,int> nums;
for(int i = 0; i < n; ++i){
int a; cin >> a;
if(nums.count(target - a)){
cout << nums[target - a] + 1 << ' ' << i + 1 << endl;
return 0;
}
nums[a] = i;
}
cout << "IMPOSSIBLE" << endl;
return 0;
}