mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 19:08:47 +00:00
A. 填数游戏
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=64546279
This commit is contained in:
parent
552f6e3464
commit
6b0ec5b8c6
54
NowCoder/contest/65194/A/A.cpp
Normal file
54
NowCoder/contest/65194/A/A.cpp
Normal 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
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
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
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
BIN
NowCoder/contest/65194/A/samples/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user