程式碼哥布林們,記得初始化
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, HIGH = 0, ans = 0;
cin >> n;
int a[n], b[n];
for(int i = 0;i < n;i++){
cin >> a[i] >> b[i];
}
for(int i = 0;i < n;i++){
HIGH = max(HIGH,b[i]);
}
vector<bool> x(HIGH, false);
for(int i = 0;i < n;i++){
for(int j = a[i];j < b[i];j++){
x[j] = 1;
}
}
for(int i = 0;i < HIGH;i++){
if(x[i]){
ans++;
}
}
cout << ans << endl;
return 0;
}