CSP 2019-3-2 买菜

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
47
48
49
50
51
52
53
54
55
56
#include  <iostream>

using namespace std;

const int N = 2005;
struct time {
int x, y;
} h[N], w[N];

int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i].x;
cin >> h[i].y;
}
for (int i = 1; i <= n; i++) {
cin >> w[i].x;
cin >> w[i].y;
}
long long aus = 0;
for (int i = 1, j = 1; i <= n && j <= n;) {
if (h[i].x < w[j].x) {
if (h[i].y <= w[j].x) {
i++;
}
else if (h[i].y <= w[j].y)
{
aus += h[i].y - w[j].x;
i++;
}
else {
aus += w[j].y - w[j].x;
j++;//
}
}
else
{
if (h[i].x >= w[j].y) {
j++;
}
else if (h[i].y >= w[j].y)
{
aus += w[j].y - h[i].x;
j++;
}
else {
aus += h[i].y - h[i].x;
i++;
}
}
}
cout << aus;
return 0;
}

最后更新: 2019年08月15日 14:56

原始链接: http://WangDeqiangCN.github.io/2019/08/15/CSP2018-9-2/

× 请我喝杯咖啡~
打赏二维码