记录编号 |
577480 |
评测结果 |
TAATAAAAAA |
题目名称 |
空图 |
最终得分 |
80 |
用户昵称 |
HeSn |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
6.766 s |
提交时间 |
2022-11-05 08:58:32 |
内存使用 |
36.25 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2000010, 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;
}