Untitled
unknown
c_cpp
2 years ago
515 B
8
Indexable
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
int b[maxn];
int main()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if(x > y) swap(x, y);
for(int j = x+1; j <= y; j++) b[j] = 1;
}
int ans = n + 1, here = 0;
for(int i = 1; i <= n+1; i++) {
if(b[i] == 0) ans += 2 * here, here = 0;
else here += b[i];
}
cout << ans << endl;
return 0;
}Editor is loading...
Leave a Comment