比赛 |
4043级NOIP2022欢乐赛3rd |
评测结果 |
EEEEEEEEEE |
题目名称 |
空图 |
最终得分 |
0 |
用户昵称 |
HeSn |
运行时间 |
2.348 s |
代码语言 |
C++ |
内存使用 |
7.26 MiB |
提交时间 |
2022-11-04 21:53:38 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 100010, inf = 1e9;
int n, m, ans;
struct node {
int w, id;
}a[MAXN];
bool cmp(node x, node y) {
return x.w < y.w;
}
bool cmp2(node x, node y) {
return x.id < y.id;
}
signed main(){
freopen("EmptyGraph.in", "r", stdin);
freopen("EmptyGraph.out", "w", stdout);
cin >> n >> m;
ans = 0;
for(int i = 1; i <= n; i ++) {
cin >> a[i].w;
a[i].id = i;
}
a[n + 1].w = 0;
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i < m; i ++) {
a[i].w = inf;
}
sort(a + 1, a + n + 1, cmp2);
// for(int i = 1; i <= n; i ++) {
// cout << a[i].w << ' ';
// }
// cout << endl;
int maxn1 = 0;
for(int i = 1; i < n; i ++) {
maxn1 = max(maxn1, min(a[i].w, a[i + 1].w));
}
int maxn2 = inf, maxn3 = inf;
for(int i = 1; i <= n; i ++) {
if(a[i].w < maxn2) {
maxn3 = maxn2;
maxn2 = a[i].w;
}
else if(a[i].w < maxn3) {
maxn3 = a[i].w;
}
}
maxn2 *= 2;
maxn3 *= 2;
for(int i = 1; i <= n; i ++) {
int x = max(maxn1, max(a[i - 1].w, a[i + 1].w));
if(a[i].w * 2 == maxn2) {
ans = max(ans, min(x, maxn3));
}
else {
ans = max(ans, min(x, maxn2));
}
}
cout << ans << endl;
return 0;
}