当前位置:网站首页>E. Best Pair
E. Best Pair
2022-07-06 04:10:00 【whitewall_ nine】
https://codeforces.com/contest/1637/problem/E
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
#define int long long
const int N = 1e4 + 10;
void solve() {
map<int, int> cnt;
int n, m;
cin >> n >> m;
vector<int> a(n);
for (auto &tt : a) {
cin >> tt;
cnt[tt] ++;
}
vector<pii> bad(m * 2);
rep(i, 1, m) {
int x, y;
cin>> x >> y;
bad.pb({x, y});
bad.pb({y, x});
}
sort(bad.begin(), bad.end());
vector<vector<int>> occ(n);
for (auto &[num, ct] : cnt) {
occ[ct].pb(num);
}
for (auto &t : occ)
reverse(t.begin(), t.end());
int ans = 0;
for (int cx = 1; cx < n; cx ++) {
for (auto x : occ[cx]) {
for (int cy = 1; cy <= cx; cy ++) {
for (auto y : occ[cy]) {
if (y != x && !binary_search(bad.begin(), bad.end(), pair<int, int>{x, y})) {
ans = max (ans, (cx + cy) * (x + y));
break;
}
}
}
}
}
cout << ans << endl;
}
signed main () {
int t;
cin >> t;
while (t --) solve();
}
I didn't think about this question before. I was thinking about what simple ideas can help me find such an answer . Actually, this question is right stl The use of , Because it is to find the maximum , So we invert all the numbers by enumerating the number , It can reduce the complexity , If you enumerate , First calculate the number , Then enumerate the enumeration times , Replace enumeration object
边栏推荐
- Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
- Python book learning notes - Chapter 09 section 01 create and use classes
- Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
- Record the pit of NETCORE's memory surge
- Database, relational database and NoSQL non relational database
- Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
- 食品行业仓储条码管理系统解决方案
- About some basic DP -- those things about coins (the basic introduction of DP)
- 图应用详解
- Simple blog system
猜你喜欢

User datagram protocol UDP
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/45/6777fa919386e526dbb0d2c808a7f2.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package
![[FPGA tutorial case 11] design and implementation of divider based on vivado core](/img/39/f337510c2647d365603a8485583a20.png)
[FPGA tutorial case 11] design and implementation of divider based on vivado core

MySql数据库root账户无法远程登陆解决办法

如何修改表中的字段约束条件(类型,default, null等)

About some basic DP -- those things about coins (the basic introduction of DP)

1291_Xshell日志中增加时间戳的功能

mysql关于自增长增长问题

Overturn your cognition? The nature of get and post requests

Comprehensive ability evaluation system
随机推荐
MySql数据库root账户无法远程登陆解决办法
Tips for using dm8huge table
Exchange bottles (graph theory + thinking)
Hashcode and equals
C language -- structs, unions, enumerations, and custom types
[disassembly] a visual air fryer. By the way, analyze the internal circuit
mysql关于自增长增长问题
Python book learning notes - Chapter 09 section 01 create and use classes
Stable Huawei micro certification, stable Huawei cloud database service practice
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
R note prophet
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
asp. Core is compatible with both JWT authentication and cookies authentication
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
Class A, B, C networks and subnet masks in IPv4
Thread sleep, thread sleep application scenarios
软考 系统架构设计师 简明教程 | 总目录
Oracle ORA error message
Detailed explanation of serialization and deserialization
Query the number and size of records in each table in MySQL database