We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
or you can store only the values which are needed to be deal with, also along with its index and then find the difference, which may be much easier:
something like this:
#include<vector>#include<map>#include<iostream>usingnamespacestd;#define ul unsigned long intintmain(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);ulT;cin>>T;for(autot=0;t<T;++t){ulm=0,n=0;multimap<ul,ul>myMap;vector<ul>vecValues;cin>>m>>n;for(autoidx=1;idx<=n;++idx){ultempFirst=0;cin>>tempFirst;if(tempFirst<=m){myMap.emplace(tempFirst,idx);vecValues.push_back(tempFirst);}}for(auto&vec:vecValues){multimap<ul,ul>::const_iteratorcurrent=myMap.find(vec);ulcurr_value=current->first;ulid=current->second;uldiff=m-curr_value;myMap.erase(current);multimap<ul,ul>::const_iteratorgett_id2=myMap.find(diff);if((gett_id2!=myMap.cend())&&(gett_id2->first+curr_value==m)){cout<<id<<" "<<gett_id2->second<<endl;break;}}}return0;}
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
or you can store only the values which are needed to be deal with, also along with its index and then find the difference, which may be much easier: something like this: