比赛 |
round 1『缺混麻酱伞鹊役』 |
评测结果 |
WWWWWWWWWWWWWWWWWWWW |
题目名称 |
HS 的 Eula |
最终得分 |
0 |
用户昵称 |
wdsjl |
运行时间 |
0.061 s |
代码语言 |
C++ |
内存使用 |
3.53 MiB |
提交时间 |
2024-11-21 09:42:02 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 510;
ll ps[N],vis[N],n,m,zuo,you,res,zuo_n,you_n;
int main(){
freopen("Eulalover.in","r",stdin);
freopen("Eulalover.out","w",stdout);
int fg=1;
int p0s;
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++){
scanf("%lld",&ps[i]);
if(ps[i]==0){
fg=0;
p0s=i;
res+=m;
}
}
if(fg){
ps[++n]=0;
}
sort(ps+1,ps+1+n);
for(int i=1;i<=n;i++){
// cout<<ps[i]<<"www";
// cout<<"RR"<<zuo<<" "<<you<<endl;
if(ps[i]<0){
zuo+=(m-(0-ps[i]));
zuo_n++;
}
if(ps[i]==0&&fg){
p0s=i;
vis[i]++;
// cout<<vis[i]<<"FFF"<<endl;
}
if(ps[i]>0){
you_n++;
you+=(m-ps[i]);
}
}
int t=0;
// for(int i=1;i<=n;i++)cout<<vis[i]<<" ";
// cout<<endl;
// cout<<zuo<<" "<<zuo_n<<" "<<you<<" "<<you_n<<endl;
for(int i=1;i<n;i++){
if(t>=m)break;
else if(zuo_n==0&&you_n==0)break;
if(zuo>=you){
// cout<<"左"<<endl;
int rr=p0s-1;
// cout<<vis[rr]<<"rr"<<endl;
while(vis[rr]&&rr>0)rr--;
t+=(ps[p0s]-ps[rr]);
you-=(ps[p0s]-ps[rr])*2*you_n;
p0s=rr;
vis[p0s]++;
res+=m-t;
zuo-=m-t;
zuo_n--;
}else if(zuo<you){
// cout<<"右"<<endl;
int rr=p0s+1;
// cout<<vis[rr]<<"rr"<<endl;
while(vis[rr]&&rr<n)rr++;
t+=(ps[rr]-ps[p0s]);
zuo-=(ps[rr]-ps[p0s])*2*zuo_n;
p0s=rr;
vis[p0s]++;
res+=m-t;
you-=m-t;
you_n--;
}
// cout<<ps[p0s]<<" "<<t<<" "<<res<<endl;
// cout<<"now"<<zuo<<" "<<zuo_n<<" "<<you<<" "<<you_n<<endl;
}
printf("%lld",res);
return 0;
}