#include <stdio.h>
#define N 100000
#define M 100000
#define INF 0x3f3f3f3f3f3f3f3f
long long cross2(int x1, int y1, int x2, int y2) {
return (long long) x1 * y2 - (long long) x2 * y1;
}
long long cross(int x0, int y0, int x1, int y1, int x2, int y2) {
return cross2(x1 - x0, y1 - y0, x2 - x0, y2 - y0);
}
int main() {
static int aa[N], bb[M], ii[N], jj[M];
int n, m, i, j, cnt;
long long ans;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (j = 0; j < m; j++)
scanf("%d", &bb[j]);
cnt = 0;
for (i = 0; i < n; i++) {
while (cnt >= 2 && cross(ii[cnt - 2], aa[ii[cnt - 2]], ii[cnt - 1], aa[ii[cnt - 1]], i, aa[i]) <= 0)
cnt--;
ii[cnt++] = i;
}
n = cnt;
cnt = 0;
for (j = 0; j < m; j++) {
while (cnt >= 2 && cross(jj[cnt - 2], bb[jj[cnt - 2]], jj[cnt - 1], bb[jj[cnt - 1]], j, bb[j]) <= 0)
cnt--;
jj[cnt++] = j;
}
m = cnt;
i = 0, j = 0, ans = 0;
while (i + 1 < n || j + 1 < m)
if (j + 1 == m || cross2(ii[i + 1] - ii[i], aa[ii[i + 1]] - aa[ii[i]], jj[j + 1] - jj[j], bb[jj[j + 1]] - bb[jj[j]]) >= 0)
ans += (long long) bb[jj[j]] * (ii[i + 1] - ii[i]), i++;
else
ans += (long long) aa[ii[i]] * (jj[j + 1] - jj[j]), j++;
printf("%lld\n", ans);
return 0;
}
Compilation message
kyoto.c: In function 'main':
kyoto.c:20:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
kyoto.c:22:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
kyoto.c:24:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%d", &bb[j]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
596 KB |
Output is correct |
5 |
Correct |
8 ms |
508 KB |
Output is correct |
6 |
Correct |
4 ms |
364 KB |
Output is correct |
7 |
Correct |
24 ms |
1052 KB |
Output is correct |
8 |
Correct |
19 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
964 KB |
Output is correct |
10 |
Correct |
20 ms |
996 KB |
Output is correct |
11 |
Correct |
20 ms |
1112 KB |
Output is correct |
12 |
Correct |
24 ms |
1172 KB |
Output is correct |
13 |
Correct |
21 ms |
972 KB |
Output is correct |
14 |
Correct |
20 ms |
980 KB |
Output is correct |
15 |
Runtime error |
21 ms |
1936 KB |
Execution killed with signal 11 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |