当前位置:网站首页>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
边栏推荐
- 10個 Istio 流量管理 最常用的例子,你知道幾個?
- 记一次excel XXE漏洞
- 【leetcode】22. bracket-generating
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Stable Huawei micro certification, stable Huawei cloud database service practice
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
- Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
- About some basic DP -- those things about coins (the basic introduction of DP)
猜你喜欢
What is the difference between gateway address and IP address in tcp/ip protocol?
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
Simple blog system
如何修改表中的字段约束条件(类型,default, null等)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
Tips for using dm8huge table
Stable Huawei micro certification, stable Huawei cloud database service practice
自动化测试的好处
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
10个 Istio 流量管理 最常用的例子,你知道几个?
随机推荐
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
Interface idempotency
20、 EEPROM memory (AT24C02) (similar to AD)
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Mlapi series - 04 - network variables and network serialization [network synchronization]
Cf464e the classic problem [shortest path, chairman tree]
如何修改表中的字段约束条件(类型,default, null等)
Mysql数据库慢sql抓取与分析
Oracle ORA error message
食品行业仓储条码管理系统解决方案
Fundamentals of SQL database operation
pd. to_ numeric
2/12 didn't learn anything
Overturn your cognition? The nature of get and post requests
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
How does technology have the ability to solve problems perfectly
Prime protocol announces cross chain interconnection applications on moonbeam
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
MySQL master-slave replication