結果

問題 No.2495 Three Sets
ユーザー achapiachapi
提出日時 2023-10-06 21:51:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 208,104 KB
実行使用メモリ 9,316 KB
最終ジャッジ日時 2023-10-06 21:51:37
合計ジャッジ時間 3,820 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 92 ms
7,668 KB
testcase_20 AC 83 ms
7,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int Na, Nb, Nc;
	cin >> Na >> Nb >> Nc;
	vector<pair<int, int>> S;
	for (int i = 0; i < Na; i++){
		int A;
		cin >> A;
		S.push_back(make_pair(A, 0));
	}
	for (int i = 0; i < Nb; i++){
		int B;
		cin >> B;
		S.push_back(make_pair(B, 1));
	}
	for (int i = 0; i < Nc; i++){
		int C;
		cin >> C;
		S.push_back(make_pair(C, 2));
	}
	int Sa = 0, Sb = 0, Sc = 0, A = 0, B = 0, C = 0;
	sort(S.rbegin(), S.rend());
	long long ans = 0;
	for (int i = 0; i < Na + Nb + Nc; i++){
		auto [p, n] = S[i];
		if (n == 0){
			Sa++;
			A += p;
		}
		if (n == 1){
			Sb++;
			B += p;
		}
		if (n == 2){
			Sc++;
			C += p;
		}
		long long m = (long long) A * Sb + (long long) B * Sc + (long long) C * Sa;
		if (ans <= m){
			ans = m;
		} else {
			if (n == 0){
				Sa--;
				A -= p;
			}
			if (n == 1){
				Sb--;
				B -= p;
			}
			if (n == 2){
				Sc--;
				C -= p;
			}
		}
	}
	cout << ans << endl;
}
0