当前位置:网站首页>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
边栏推荐
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- Ks008 SSM based press release system
- Comprehensive ability evaluation system
- KS003基于JSP和Servlet实现的商城系统
- Mysql数据库慢sql抓取与分析
- Detailed explanation of serialization and deserialization
- Basic knowledge of binary tree, BFC, DFS
- Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
- Ipv4中的A 、B、C类网络及子网掩码
- Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)

Record the pit of NETCORE's memory surge

绑定在游戏对象上的脚本的执行顺序

Security xxE vulnerability recurrence (XXe Lab)

图应用详解

记一次excel XXE漏洞

Cross domain and jsonp details

C (thirty) C combobox listview TreeView

Class A, B, C networks and subnet masks in IPv4

综合能力测评系统
随机推荐
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
Ipv4中的A 、B、C类网络及子网掩码
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
【按键消抖】基于FPGA的按键消抖模块开发
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
Redis (replicate dictionary server) cache
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
Codeforces Round #770 (Div. 2) B. Fortune Telling
WPF effect Article 191 box selection listbox
Proof of Stirling formula
MySQL about self growth
脚本生命周期
2/11 matrix fast power +dp+ bisection
判断当天是当月的第几周
Cross domain and jsonp details
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
51nod 1130 n factorial length V2 (Stirling approximation)
Ks003 mall system based on JSP and Servlet