fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6. long long n;
  7. cin>>n;
  8. map<long long, long long>Ox;
  9. long long dis=0,A=0,B=0;//distance
  10. bool zero_dis=0;
  11. for(long long i=1;i<=n && !zero_dis;i++){
  12. long long tmp;
  13. cin>>tmp;
  14. if(Ox[tmp]!=0){
  15. zero_dis=true;
  16. A=Ox[tmp];
  17. B=i;
  18. dis=0;
  19. }
  20. else Ox[tmp]=i;
  21. }
  22.  
  23. if(!zero_dis){
  24. dis=-1;
  25. for(auto i= Ox.begin(),j=++Ox.begin(); j!=Ox.end(); i++, j++){//cout<<j->first<<" "<<i->first<<endl;
  26. long long tmp_dis=j->first-i->first;
  27. if(dis>tmp_dis||dis<0){
  28. dis=tmp_dis;
  29. A=j->second;
  30. B=i->second;
  31. }
  32. }
  33. }
  34. cout<<dis<<"\n"<<A<<" "<<B;
  35. return 0;
  36. }
Success #stdin #stdout 0s 15240KB
stdin
10
0 1 5 10 20 100 120 250 -100 55 
stdout
-240
142 8