#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n, m;
ll a[100010], b[100010];
ll arr[100010];
vector<pll> cvh;
vector<ll> A, B;
ll ans, x, y;
ll ccw(pll X, pll Y, pll Z)
{
return (X.fi * Y.se + Y.fi * Z.se + Z.fi * X.se) - (X.se * Y.fi + Y.se * Z.fi + Z.se * X.fi);
}
void f(ll siz)
{
cvh.clear();
for(ll i = 1 ; i <= siz ; i++)
{
while(cvh.size() >= 2)
{
ll now = (ll)cvh.size();
if(ccw(cvh[now - 2], cvh[now - 1], {i, arr[i]}) <= 0)
cvh.pop_back();
else
break;
}
cvh.push_back({i, arr[i]});
}
}
int main(void)
{
fastio
cin >> n >> m;
for(ll i = 1 ; i <= n ; i++)
cin >> a[i];
for(ll i = 1 ; i <= m ; i++)
cin >> b[i];
for(ll i = 1 ; i <= n ; i++)
arr[i] = a[i];
f(n);
for(auto &i : cvh)
A.push_back(i.fi);
for(ll i = 1 ; i <= m ; i++)
arr[i] = b[i];
f(m);
for(auto &i : cvh)
B.push_back(i.fi);
x = 0, y = 0;
ll sizA = (ll)A.size(), sizB = (ll)B.size();
while(1)
{
if(x == sizA - 1 && y == sizB - 1)
break;
pll gapA, gapB;
gapA = {INF, 1};
gapB = {INF, 1};
if(x < sizA - 1)
gapA = {a[A[x + 1]] - a[A[x]], A[x + 1] - A[x]};
if(y < sizB - 1)
gapB = {b[B[y + 1]] - b[B[y]], B[y + 1] - B[y]};
if(gapA.fi * gapB.se > gapB.fi * gapA.se)
{
ans += a[A[x]] * (B[y + 1] - B[y]);
y++;
}
else
{
ans += b[B[y]] * (A[x + 1] - A[x]);
x++;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Runtime error |
2 ms |
4724 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Runtime error |
3 ms |
4696 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Runtime error |
2 ms |
4724 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |