Mọi người chỉ cho em vì sao code này lại bị vòng lặp vô hạn ạ. Em cảm ơn. Nếu mọi người cần đề https://vnspoj.github.io/problems/BWPOINTS.html
#include <bits/stdc++.h>
using namespace std;
int d = 0;
int main () {
vector <int> a (100002);
vector <int> b (100002);
int n;
cin >> n;
for (int i = 0; i < n;i++) {
cin >> a[i];
}
for (int i = 0; i < n;i++) {
cin >> b[i];
}
sort (a.begin(), a.end());
sort (b.begin(), b.end());
int j = 0;
int i = 0;
int res;
while (i<= n-1&&j<=n-1) {
if (a[i] > b[j]) {
res = a[i];
d++;
i++;
while (b[j] < res&&j<=n-1) {
if (j==n-1) d--;
j++;
}
}
if (b[j] > a[i]) {
res = b[j];
d++;
i++;
j++;
while (a[i] < res&&i<=n-1) {
i++;
if (i==n-1) d--;
}
}
}
cout << d;
return 0;
}