0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-08 02:45:26 +00:00
Baoshuo Ren 2023-10-17 22:32:38 +08:00
parent 552f6e3464
commit 6b0ec5b8c6
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
5 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,54 @@
#include <iostream>
#include <algorithm>
#include <functional>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, m, a[N], b[N];
long long ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
}
std::sort(a + 1, a + 1 + n, std::greater<>());
std::sort(b + 1, b + 1 + m, std::greater<>());
int i = 1;
for (; i <= n && a[i] >= 0 && b[i] >= 0; i++) {
ans += static_cast<long long>(a[i]) * b[i];
}
std::sort(a + i, a + 1 + n);
std::sort(b + i, b + 1 + m);
for (; i <= n && a[i] < 0 && b[i] < 0; i++) {
ans += static_cast<long long>(a[i]) * b[i];
}
std::sort(a + i, a + 1 + n, std::greater<>());
std::sort(b + i, b + 1 + m, std::greater<>());
for (; i <= n; i++) {
ans += static_cast<long long>(a[i]) * b[i];
}
cout << ans << endl;
return 0;
}

BIN
NowCoder/contest/65194/A/samples/1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
NowCoder/contest/65194/A/samples/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
NowCoder/contest/65194/A/samples/2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
NowCoder/contest/65194/A/samples/2.in (Stored with Git LFS) Normal file

Binary file not shown.