I run this Program and ouput is correct
Everything seems to be fine …
please help. what’s wrong in this program
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> a1,a2,a3;
int n,p1,p2,diff;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&p1);
a1.push_back(p1);
scanf("%d",&p2);
a2.push_back(p2);
diff=p1-p2;
a3.push_back(diff);
}
vector<int>::const_iterator it,it2;
it = max_element(a3.begin(), a3.end());
it2 = min_element(a3.begin(), a3.end());
int a=1;
int b=2;
if(abs(*it)>abs(*it2))
{
cout<<a;
cout<<endl<<abs(*it);
}
else
{
cout<<b;
cout<<endl<<abs(*it2);
}
return 0;
}