#include <iostream>
#include <vector>
#include <map>
#include <stdlib.h>
int main()
{
int comparevalue = 3;
typedef std::vector<int> intvec;
intvec myvec;
myvec.push_back(1);
myvec.push_back(2);
myvec.push_back(4);
myvec.push_back(5);
myvec.push_back(6);
myvec.push_back(7);
typedef std::map<int, int> intmap;
intmap mymap;
for (intvec::const_iterator itr = myvec.begin(); itr != myvec.end(); ++itr)
mymap.insert(std::make_pair(abs(*itr-comparevalue), *itr));
std::cout << "difference:" << mymap.begin()->first << "\n";
std::cout << "value:" << mymap.begin()->second;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c3RkbGliLmg+CgppbnQgbWFpbigpCnsKICAgIGludCBjb21wYXJldmFsdWUgPSAzOwogICAgdHlwZWRlZiBzdGQ6OnZlY3RvcjxpbnQ+IGludHZlYzsKICAgIGludHZlYyBteXZlYzsKICAgIAogICAgbXl2ZWMucHVzaF9iYWNrKDEpOwogICAgbXl2ZWMucHVzaF9iYWNrKDIpOwogICAgbXl2ZWMucHVzaF9iYWNrKDQpOwogICAgbXl2ZWMucHVzaF9iYWNrKDUpOwogICAgbXl2ZWMucHVzaF9iYWNrKDYpOwogICAgbXl2ZWMucHVzaF9iYWNrKDcpOwogICAgCiAgICB0eXBlZGVmIHN0ZDo6bWFwPGludCwgaW50PiBpbnRtYXA7CiAgICBpbnRtYXAgbXltYXA7CiAgICAKICAgIGZvciAoaW50dmVjOjpjb25zdF9pdGVyYXRvciBpdHIgPSBteXZlYy5iZWdpbigpOyBpdHIgIT0gbXl2ZWMuZW5kKCk7ICsraXRyKQogICAgICAgIG15bWFwLmluc2VydChzdGQ6Om1ha2VfcGFpcihhYnMoKml0ci1jb21wYXJldmFsdWUpLCAqaXRyKSk7CiAgICAKICAgIHN0ZDo6Y291dCA8PCAiZGlmZmVyZW5jZToiIDw8IG15bWFwLmJlZ2luKCktPmZpcnN0IDw8ICJcbiI7CiAgICBzdGQ6OmNvdXQgPDwgInZhbHVlOiIgPDwgbXltYXAuYmVnaW4oKS0+c2Vjb25kOwogICAgcmV0dXJuIDA7Cn0=