From 6b0ec5b8c63b4efb8ae8a53097ce4e9e00ff85f4 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 17 Oct 2023 22:32:38 +0800 Subject: [PATCH] =?UTF-8?q?A.=20=E5=A1=AB=E6=95=B0=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://ac.nowcoder.com/acm/contest/view-submission?submissionId=64546279 --- NowCoder/contest/65194/A/A.cpp | 54 ++++++++++++++++++++++++++ NowCoder/contest/65194/A/samples/1.ans | 3 ++ NowCoder/contest/65194/A/samples/1.in | 3 ++ NowCoder/contest/65194/A/samples/2.ans | 3 ++ NowCoder/contest/65194/A/samples/2.in | 3 ++ 5 files changed, 66 insertions(+) create mode 100644 NowCoder/contest/65194/A/A.cpp create mode 100644 NowCoder/contest/65194/A/samples/1.ans create mode 100644 NowCoder/contest/65194/A/samples/1.in create mode 100644 NowCoder/contest/65194/A/samples/2.ans create mode 100644 NowCoder/contest/65194/A/samples/2.in diff --git a/NowCoder/contest/65194/A/A.cpp b/NowCoder/contest/65194/A/A.cpp new file mode 100644 index 00000000..6713095d --- /dev/null +++ b/NowCoder/contest/65194/A/A.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +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(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(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(a[i]) * b[i]; + } + + cout << ans << endl; + + return 0; +} diff --git a/NowCoder/contest/65194/A/samples/1.ans b/NowCoder/contest/65194/A/samples/1.ans new file mode 100644 index 00000000..cb90f684 --- /dev/null +++ b/NowCoder/contest/65194/A/samples/1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06e9d52c1720fca412803e3b07c4b228ff113e303f4c7ab94665319d832bbfb7 +size 2 diff --git a/NowCoder/contest/65194/A/samples/1.in b/NowCoder/contest/65194/A/samples/1.in new file mode 100644 index 00000000..5389d495 --- /dev/null +++ b/NowCoder/contest/65194/A/samples/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e7ad5d29d788541f8b073136bb4ce2ed82b197cc0afd65e608cd72b1d3e7d98 +size 16 diff --git a/NowCoder/contest/65194/A/samples/2.ans b/NowCoder/contest/65194/A/samples/2.ans new file mode 100644 index 00000000..671f9d17 --- /dev/null +++ b/NowCoder/contest/65194/A/samples/2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da30cf2c26ade60c341c80f5dd301517d4ca2bafdfff86ed430f975a4387c177 +size 14 diff --git a/NowCoder/contest/65194/A/samples/2.in b/NowCoder/contest/65194/A/samples/2.in new file mode 100644 index 00000000..7e8bbe4a --- /dev/null +++ b/NowCoder/contest/65194/A/samples/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79d76fbd39f40f5b83c9623110fb84774c9c9ee38259829b54c5acc03b8afc1d +size 8583