Submission #3596242
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
void solve() {
int W, H;
cin >> W >> H;
vector<ll> P(W), Q(H);
for (int i = 0; i < W; i++) {
cin >> P[i];
}
for (int i = 0; i < H; i++) {
cin >> Q[i];
}
sort(all(P));
sort(all(Q));
int p = 0, q = 0;
ll ans = 0;
while(p < W && q < H) {
if (P[p] < Q[q]) {
ans += P[p] * (1 + H - q);
p++;
} else {
ans += Q[q] * (1 + W - p);
q++;
}
}
while(p < W) {
ans += P[p] * (1 + H - q);
p++;
}
while(q < H) {
ans += Q[q] * (1 + W - p);
q++;
}
cout << ans << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Gr-idian MST |
User |
kakira |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
1543 Byte |
Status |
AC |
Exec Time |
34 ms |
Memory |
1792 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
34 ms |
1792 KB |
02.txt |
AC |
33 ms |
1792 KB |
03.txt |
AC |
34 ms |
1792 KB |
04.txt |
AC |
34 ms |
1792 KB |
05.txt |
AC |
34 ms |
1792 KB |
06.txt |
AC |
33 ms |
1792 KB |
07.txt |
AC |
34 ms |
1792 KB |
08.txt |
AC |
33 ms |
1792 KB |
09.txt |
AC |
34 ms |
1792 KB |
10.txt |
AC |
34 ms |
1792 KB |
11.txt |
AC |
29 ms |
1792 KB |
12.txt |
AC |
28 ms |
1792 KB |
13.txt |
AC |
24 ms |
1792 KB |
14.txt |
AC |
32 ms |
1792 KB |
15.txt |
AC |
33 ms |
1792 KB |
16.txt |
AC |
17 ms |
1024 KB |
17.txt |
AC |
17 ms |
1024 KB |
18.txt |
AC |
17 ms |
1024 KB |
19.txt |
AC |
17 ms |
1024 KB |
20.txt |
AC |
15 ms |
1792 KB |
21.txt |
AC |
24 ms |
1792 KB |
22.txt |
AC |
24 ms |
1792 KB |
23.txt |
AC |
20 ms |
1792 KB |
24.txt |
AC |
23 ms |
1792 KB |
25.txt |
AC |
1 ms |
256 KB |
26.txt |
AC |
1 ms |
256 KB |
27.txt |
AC |
1 ms |
256 KB |
28.txt |
AC |
1 ms |
256 KB |
s1.txt |
AC |
1 ms |
256 KB |
s2.txt |
AC |
1 ms |
256 KB |