結果

問題 No.2495 Three Sets
ユーザー 👑 kmjpkmjp
提出日時 2023-10-06 23:57:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,247 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 208,836 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-10-06 23:57:55
合計ジャッジ時間 27,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N[3];
ll A[3][6060];
ll num[3][6060];
ll S[3][6060];

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) {
		return ((__int128)(B.second-C.second)*(B.first-A.first)<=(__int128)(A.second-B.second)*(C.first-B.first));
	}
	void add(V a, V b) { // add ax+b
		if(Q.size() && Q.back().first==a) {
			//aが同じ場合
			//if(b>=Q.back().second) return; //minの場合
			if(b<=Q.back().second) return; //maxの場合
			Q.pop_back();
		}
		Q.push_back({a,b});
		int v;
		while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))
			Q[v-2]=Q[v-1], Q.pop_back();
	}
	void add(vector<pair<V,V>> v) {
		//sort(v.begin(),v.end());
		for(auto r=v.begin();r!=v.end();r++) add(r->first,r->second);
	}
	
	
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			(0^((calc(Q[M],x)<=calc(Q[M+1],x)))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,3) cin>>N[i];
	FOR(i,3) {
		FOR(j,N[i]) {
			cin>>x;
			A[i][3000-x]++;
		}
		FOR(j,6001) {
			num[i][j+1]=num[i][j]+A[i][j];
			S[i][j+1]=S[i][j]+A[i][j]*(3000-j);
		}
	}
	ll ma=0;
	FOR(i,6001) {
		vector<pair<ll,ll>> X;
		for(j=6000;j>=0;j--) {
			X.push_back({S[1][j],num[1][j]*S[0][i]});
		}
		ConvexHull<ll> ch;
		ch.add(X);
		FOR(j,6001) {
			ma=max(ma,ch.query(num[2][j])+num[0][i]*S[2][j]);
		}
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0