比赛 |
4043级NOIP2022欢乐赛3rd |
评测结果 |
AAAAAAAAAA |
题目名称 |
空图 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
2.671 s |
代码语言 |
C++ |
内存使用 |
28.62 MiB |
提交时间 |
2022-11-04 21:12:22 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2000000+5;
int a[N];
struct sdf{
int val,id;
}b[N];
bool cmp(sdf x,sdf y){
if (x.val!=y.val)return x.val<y.val;
return x.id<y.id;
}
int main(){
freopen("EmptyGraph.in","r",stdin);
freopen("EmptyGraph.out","w",stdout);
int n,k;scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);b[i]={a[i],i};
}
sort(b+1,b+n+1,cmp);b[n+1].id=1;
int tmp=a[b[k].id];
for (int i=1;i<=k;i++)a[b[i].id]=1e9;
int mx=0,pos=a[b[k+1].id];
for (int i=1;i<n;i++){
mx=max(mx,min(min(a[i],a[i+1]),2*pos));
mx=min(mx,1000000000);
}
if (k>=2)mx=max(mx,min(1000000000,2*tmp));
else mx=max(mx,min(2*tmp,b[n].val));
printf("%d\n",mx);
return 0;
}