#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct pt {
int x, y;
pt(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
};
bool ccw(const pt& a, const pt& b, const pt& c) {
return (LL)(b.x - a.x) * (c.y - b.y) - (LL)(c.x - b.x) * (b.y - a.y) > 0;
}
const int N = 100005;
int n, m, n1, n2, a[N], b[N];
double x[N], y[N];
LL res;
pt l1[N], l2[N];
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) {
scanf("%d", a + i);
pt nw(i, a[i]);
while(n1 > 1 && !ccw(l1[n1 - 2], l1[n1 - 1], nw)) --n1;
l1[n1++] = nw;
}
for(int i = 0; i < m; ++i) {
scanf("%d", b + i);
pt nw(i, b[i]);
while(n2 > 1 && !ccw(l2[n2 - 2], l2[n2 - 1], nw)) --n2;
l2[n2++] = nw;
}
x[0] = -1e18;
for(int i = 1; i < n1; ++i) {
x[i] = (double)(l1[i].y - l1[i - 1].y) / (l1[i].x - l1[i - 1].x);
}
y[0] = -1e18;
for(int i = 1; i < n2; ++i) {
y[i] = (double)(l2[i].y - l2[i - 1].y) / (l2[i].x - l2[i - 1].x);
}
for(int i = n1 - 1, j = n2 - 1; i || j; ) {
if(x[i] > y[j]) {
res += (LL)l2[j].y * (l1[i].x - l1[i - 1].x);
--i;
}
else {
res += (LL)l1[i].y * (l2[j].x - l2[j - 1].x);
--j;
}
}
printf("%lld", res);
return 0;
}
Compilation message
kyoto.cpp: In function 'int main()':
kyoto.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
kyoto.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", b + i);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
1 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1920 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
9 ms |
2092 KB |
Output is correct |
5 |
Correct |
7 ms |
2132 KB |
Output is correct |
6 |
Correct |
4 ms |
2004 KB |
Output is correct |
7 |
Correct |
18 ms |
2520 KB |
Output is correct |
8 |
Correct |
18 ms |
2648 KB |
Output is correct |
9 |
Correct |
19 ms |
2628 KB |
Output is correct |
10 |
Correct |
18 ms |
2644 KB |
Output is correct |
11 |
Correct |
17 ms |
2644 KB |
Output is correct |
12 |
Correct |
22 ms |
2620 KB |
Output is correct |
13 |
Correct |
18 ms |
2636 KB |
Output is correct |
14 |
Correct |
16 ms |
2644 KB |
Output is correct |
15 |
Correct |
18 ms |
2548 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
1 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1920 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
1 ms |
1876 KB |
Output is correct |
29 |
Correct |
1 ms |
1876 KB |
Output is correct |
30 |
Correct |
1 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1876 KB |
Output is correct |
32 |
Correct |
9 ms |
2092 KB |
Output is correct |
33 |
Correct |
7 ms |
2132 KB |
Output is correct |
34 |
Correct |
4 ms |
2004 KB |
Output is correct |
35 |
Correct |
18 ms |
2520 KB |
Output is correct |
36 |
Correct |
18 ms |
2648 KB |
Output is correct |
37 |
Correct |
19 ms |
2628 KB |
Output is correct |
38 |
Correct |
18 ms |
2644 KB |
Output is correct |
39 |
Correct |
17 ms |
2644 KB |
Output is correct |
40 |
Correct |
22 ms |
2620 KB |
Output is correct |
41 |
Correct |
18 ms |
2636 KB |
Output is correct |
42 |
Correct |
16 ms |
2644 KB |
Output is correct |
43 |
Correct |
18 ms |
2548 KB |
Output is correct |
44 |
Correct |
1 ms |
1876 KB |
Output is correct |
45 |
Correct |
1 ms |
1876 KB |
Output is correct |
46 |
Correct |
1 ms |
1876 KB |
Output is correct |
47 |
Correct |
1 ms |
1876 KB |
Output is correct |
48 |
Correct |
1 ms |
1876 KB |
Output is correct |
49 |
Correct |
1 ms |
1876 KB |
Output is correct |
50 |
Correct |
1 ms |
1876 KB |
Output is correct |
51 |
Correct |
1 ms |
1876 KB |
Output is correct |
52 |
Correct |
1 ms |
1876 KB |
Output is correct |
53 |
Correct |
1 ms |
1876 KB |
Output is correct |
54 |
Correct |
1 ms |
1876 KB |
Output is correct |
55 |
Correct |
12 ms |
2180 KB |
Output is correct |
56 |
Correct |
1 ms |
1876 KB |
Output is correct |
57 |
Correct |
2 ms |
1876 KB |
Output is correct |
58 |
Correct |
5 ms |
1876 KB |
Output is correct |
59 |
Correct |
27 ms |
2608 KB |
Output is correct |
60 |
Correct |
26 ms |
2584 KB |
Output is correct |
61 |
Correct |
24 ms |
2636 KB |
Output is correct |
62 |
Correct |
27 ms |
2636 KB |
Output is correct |
63 |
Correct |
24 ms |
3312 KB |
Output is correct |
64 |
Correct |
24 ms |
2636 KB |
Output is correct |
65 |
Correct |
25 ms |
2548 KB |
Output is correct |
66 |
Correct |
23 ms |
2636 KB |
Output is correct |
67 |
Correct |
24 ms |
2644 KB |
Output is correct |