I am just teaching myself C++ programming and I was wondering if someone could critique this solution and tell me why it gives a wrong answer. For small solutions it gives the correct answers in my tests, but it gives a wrong answer when submitted. Any suggestions?
#include <iostream>
using namespace std;
int main () {
int N=0;
cin >> N;
int i=0, winner=0, lead=0, P1s=0, P2s=0;
while (i < N) {
cin >> P1s >> P2s;
if (lead < (P1s-P2s)) {
winner = 1;
lead = (P1s-P2s);
}
else if (lead < (P2s-P1s)) {
winner = 2;
lead = (P2s-P1s);
}
i++;
}
cout << winner << " " << lead << endl;
return 0;
}