#include <bits/stdc++.h>
using namespace std;
vector<int> twoSum(vector<int>& nums, int target) {
map<int, int> indexMap;
vector<int> result;
int n = nums.size();
for(int i = 0; i < n; i++){
if(indexMap.find(nums[i] - target) != indexMap.end()){
result.push_back(indexMap[nums[i]]);
result.push_back(i);
} else{
indexMap[nums[i]] = i;
}
}
return result;
}
int main() {
map<int, int> indexMap;
vector<int> result, nums(4);
nums[0] = 3; nums[1] = 2; nums[2] = 6; nums[3] = 5;
int target = 5;
int n = nums.size();
for(int i = 0; i < n; i++){
if(indexMap.find(target - nums[i]) != indexMap.end()){
result.push_back(indexMap[nums[i]]);
result.push_back(i);
cout << indexMap[target - nums[i]] << " " << i << endl;
break;
} else{
indexMap[nums[i]] = i;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnZlY3RvcjxpbnQ+IHR3b1N1bSh2ZWN0b3I8aW50PiYgbnVtcywgaW50IHRhcmdldCkgewogICAgbWFwPGludCwgaW50PiBpbmRleE1hcDsKICAgIHZlY3RvcjxpbnQ+IHJlc3VsdDsKICAgIGludCBuID0gbnVtcy5zaXplKCk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBpZihpbmRleE1hcC5maW5kKG51bXNbaV0gLSB0YXJnZXQpICE9IGluZGV4TWFwLmVuZCgpKXsKICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhpbmRleE1hcFtudW1zW2ldXSk7CiAgICAgICAgICAgIHJlc3VsdC5wdXNoX2JhY2soaSk7CiAgICAgICAgfSBlbHNlewogICAgICAgICAgICBpbmRleE1hcFtudW1zW2ldXSA9IGk7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJlc3VsdDsKfQppbnQgbWFpbigpIHsKCW1hcDxpbnQsIGludD4gaW5kZXhNYXA7CiAgICB2ZWN0b3I8aW50PiByZXN1bHQsIG51bXMoNCk7CiAgICBudW1zWzBdID0gMzsgbnVtc1sxXSA9IDI7IG51bXNbMl0gPSA2OyBudW1zWzNdID0gNTsKICAgIGludCB0YXJnZXQgPSA1OwogICAgaW50IG4gPSBudW1zLnNpemUoKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgIGlmKGluZGV4TWFwLmZpbmQodGFyZ2V0IC0gbnVtc1tpXSkgIT0gaW5kZXhNYXAuZW5kKCkpewogICAgICAgICAgICByZXN1bHQucHVzaF9iYWNrKGluZGV4TWFwW251bXNbaV1dKTsKICAgICAgICAgICAgcmVzdWx0LnB1c2hfYmFjayhpKTsKICAgICAgICAgICAgY291dCA8PCBpbmRleE1hcFt0YXJnZXQgLSBudW1zW2ldXSA8PCAiICIgPDwgaSA8PCBlbmRsOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9IGVsc2V7CiAgICAgICAgICAgIGluZGV4TWFwW251bXNbaV1dID0gaTsKICAgICAgICB9CiAgICB9CglyZXR1cm4gMDsKfQ==