AcWing 3263. 买菜
原题链接
简单
作者:
Value
,
2021-04-10 12:24:52
,
所有人可见
,
阅读 436
#include <iostream>
#define x first
#define y second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2e3 + 10;
pii a[N], b[N];
ll cmp(int i, int j){
if(a[i].x <= b[j].x && b[j].x <= a[i].y) return min(a[i].y, b[j].y) - b[j].x;
else if(a[i].x >= b[j].x && a[i].x <= b[j].y) return min(b[j].y, a[i].y) - a[i].x;
return 0;
}
int main(){
int n; cin >> n;
for(int i = 0; i < n; i ++ ) cin >> a[i].x >> a[i].y;
for(int i = 0; i < n; i ++ ) cin >> b[i].x >> b[i].y;
ll res = 0;
for(int i = 0; i < n; i ++ )
for(int j = 0; j <= n; j ++ )
res += cmp(i, j);
cout << res << endl;
return 0;
}