Codeforces Global Round 19 E. Best Pair

Posted thusloop

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Global Round 19 E. Best Pair相关的知识,希望对你有一定的参考价值。

Best Pair
题意:cntx 为x出现次数 f(x,y) = (cntx+cnty)*(x+y); 求不被禁用的最大f(x,y);
思路:按cnt (出现次数)分类 ,最多有 根号n类 再去枚举x,y

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=8e18;
const int maxn=3e5+100;
int a[maxn];
vector<int> cnt[maxn];
bool cmp(int a,int b)

	return a>b;

signed main()

	IOS
	int tt;
	cin>>tt;
	while(tt--)
	
		int n,m;
		map<int,int>mp;
		map<pii,bool>mp2;
		cin>>n>>m;
		for(int i=1; i<=n; i++)
		
			cin>>a[i];
			mp[a[i]]++;
		
		vector<int>v;
		int mx=0;
		for(int i=1; i<=m; i++)
		
			int x,y;
			cin>>x>>y;
			mp2[ x,y]=1;
			mp2[ y,x]=1;
		
		for(auto it:mp)
		
			if(cnt[it.se].empty())
			
				v.pb(it.se);
			
			cnt[it.se].pb(it.fi);
		

		for(int i=1;i<=n;i++) sort(cnt[i].begin(),cnt[i].end(),cmp);

		
		for(int i=0; i<v.size(); i++)
		
			for(int j=i; j<v.size(); j++)
			
				bool fg=0;
				int tp=0;
			//	cout<<v[i]<<" "<<v[j]<<"\\n";
				for(auto it1:cnt[v[j]])
				
					for(auto it2:cnt[v[i]])
					
						//tp++;
						if((it1+it2)*(v[i]+v[j])<=mx)break;//剪枝 否则会mle
						if(i==j&&it1==it2)continue;
						if(mp2[it1,it2])continue;
						if((it1+it2)*(v[i]+v[j])>mx)
						
							mx=(it1+it2)*(v[i]+v[j]);
						
						break;
					
				 
				//cout<<tp<<" "<<j<<"\\n";				
			
			//cout<<i<<"\\n";
		
		//for(auto it:v)cout<<it<<" ";
		cout<<mx<<"\\n";
		for(int i=1; i<=n; i++) cnt[i].clear();
	

以上是关于Codeforces Global Round 19 E. Best Pair的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Global Round 1

Codeforces Global Round 1

Codeforces Global Round 1

Codeforces Global Round 1

Codeforces Global Round 19

Codeforces Global Round 1 AParity