結果

問題 No.2495 Three Sets
ユーザー cho435cho435
提出日時 2023-10-06 21:59:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,319 bytes
コンパイル時間 4,770 ms
コンパイル使用メモリ 264,716 KB
実行使用メモリ 7,536 KB
最終ジャッジ日時 2023-10-06 21:59:52
合計ジャッジ時間 6,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int na,nb,nc;
	cin>>na>>nb>>nc;
	vector<int> a(na),b(nb),c(nc);
	rep(i,na) cin>>a.at(i);
	rep(i,nb) cin>>b.at(i);
	rep(i,nc) cin>>c.at(i);
	priority_queue<ll> pa,pb,pc;
	ll sma=0,smb=0,smc=0;
	ll ca=0,cb=0,cc=0;
	rep(i,na){
		if(a.at(i)>0){
			sma+=a.at(i);
			ca++;
		}else{
			pa.push(a.at(i));
		}
	}
	rep(i,nb){
		if(b.at(i)>0){
			smb+=b.at(i);
			cb++;
		}else{
			pb.push(b.at(i));
		}
	}
	rep(i,nc){
		if(c.at(i)>0){
			smc+=c.at(i);
			cc++;
		}else{
			pc.push(c.at(i));
		}
	}
	while(!pa.empty()||!pb.empty()||!pc.empty()){
		ll ndf=0;
		int d=-1;
		if(!pa.empty()){
			ll ad=pa.top();
			ll df=smc+cb*ad;
			if(ndf<df){
				ndf=df;
				d=0;
			}
		}
		if(!pb.empty()){
			ll ad=pb.top();
			ll df=sma+cc*ad;
			if(ndf<df){
				ndf=df;
				d=1;
			}
		}
		if(!pc.empty()){
			ll ad=pc.top();
			ll df=smb+ca*ad;
			if(ndf<df){
				ndf=df;
				d=2;
			}
		}
		if(ndf==0) break;
		if(d==0){
			ll ad=pa.top();
			pa.pop();
			sma+=ad;
			ca++;
		}else if(d==1){
			ll ad=pb.top();
			pb.pop();
			smb+=ad;
			cb++;
		}else{
			ll ad=pc.top();
			pc.pop();
			smc+=ad;
			cc++;
		}
	}
	cout<<sma*cb+smb*cc+smc*ca<<endl;
}
0