-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20180902.cpp
46 lines (45 loc) · 926 Bytes
/
20180902.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
struct H
{
int s, e;
} h[2001];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i)
{
scanf("%d%d", &h[i].s, &h[i].e);
}
long long t = 0;
int c, d;
for (int i = 0; i < n; ++i)
{
scanf("%d%d", &c, &d);
for (int j = 0; j < n; ++j)
{
if (c >= h[j].s && c < h[j].e)
{
if (d < h[j].e)
{
t += d - c;
break;
}
else if (d > h[j].e)
t += (h[j].e - c);
}
else if (d > h[j].s && d <= h[j].e)
{
t += d - h[j].s;
break;
}
else if (c <= h[j].s && d >= h[j].e)
{
t += h[j].e - h[j].s;
}
}
}
cout << t;
return 0;
}