結果

問題 No.3409 How Many Gift Boxes?
コンテスト
ユーザー shobonvip
提出日時 2025-12-21 01:02:07
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,873 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,710 ms
コンパイル使用メモリ 264,212 KB
実行使用メモリ 22,620 KB
最終ジャッジ日時 2025-12-21 01:02:22
合計ジャッジ時間 13,657 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
	author:  shobonvip
	created: 2025.12.21 00:54:01
**/

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint1000000007 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int h, w;
	cin >> h >> w;

	vector<ll> a(h), b(w);
	rep(i,0,h) cin >> a[i];
	rep(i,0,w) cin >> b[i];

	map<ll,pair<ll,ll>> mp;
	rep(i,0,h) mp[a[i]].first++;
	rep(i,0,w) mp[b[i]].second++;

	vector<pair<ll,int>> p;
	rep(i,0,h) p.emplace_back(a[i],0);
	rep(i,0,w) p.emplace_back(b[i],1);
	sort(all(p));
	reverse(all(p));

	ll a_num = 0, b_num = 0;
	mint ans_min = 0;
	mint ans_max = 0;
	for (auto [x,dat]: mp) {
		ans_min += mint(max(dat.first,dat.second))*x;
	}

	for (auto [x,t]: p) {
		if (t == 0) {
			a_num++;
			ans_max += mint(b_num) * x;
		} else {
			b_num++;
			ans_max += mint(a_num) * x;
		}
	}



	cout << ans_min.val() << '\n';
	cout << ans_max.val() << '\n';
}

0