Submission #1652869


Source Code Expand

//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int main() {
	int W, H;
	cin >> W >> H;
	
	Vec< lint > p(W+1), q(H+1);
	for_(i,0,W) cin >> p[i];
	for_(i,0,H) cin >> q[i];
	
	p[W] = q[H] = (lint)1e9;
	
	sort(allof(p));
	sort(allof(q));
	
	int i = 0, j = 0;
	lint ans = 0;
	while (i < W || j < H) {
		if (p[i] < q[j]) {
			ans += p[i] * (H+1-j);
			++i;
		} else {
			ans += q[j] * (W+1-i);
			++j;
		}
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Submission Info

Submission Time
Task C - Gr-idian MST
User tsukasa_diary
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1811 Byte
Status AC
Exec Time 88 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 30
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 87 ms 1792 KB
02.txt AC 87 ms 1792 KB
03.txt AC 87 ms 1792 KB
04.txt AC 86 ms 1792 KB
05.txt AC 86 ms 1792 KB
06.txt AC 86 ms 1792 KB
07.txt AC 86 ms 1792 KB
08.txt AC 86 ms 1792 KB
09.txt AC 86 ms 1792 KB
10.txt AC 86 ms 1792 KB
11.txt AC 81 ms 1792 KB
12.txt AC 81 ms 1792 KB
13.txt AC 77 ms 1792 KB
14.txt AC 85 ms 1792 KB
15.txt AC 88 ms 1792 KB
16.txt AC 44 ms 1024 KB
17.txt AC 44 ms 1024 KB
18.txt AC 44 ms 1024 KB
19.txt AC 44 ms 1024 KB
20.txt AC 34 ms 1792 KB
21.txt AC 60 ms 1792 KB
22.txt AC 60 ms 1792 KB
23.txt AC 59 ms 1792 KB
24.txt AC 83 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