题解
假如 \(y=1\) 该如何添加?
然后逐步推导
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[200005];
bool cmp(int x,int y)
{
if(x%2!=y%2) return x%2<y%2;
else return x<y;
}
void solve()
{
int n,x,y;
cin>>n>>x>>y;
for(int i=1;i<=x;i++) cin>>a[i];
sort(a+1,a+1+x);
vector<int> d;
for(int i=1;i<=x;i++) d.push_back((a[i]+n-a[(i-2+x)%x+1])%n);
sort(d.begin(),d.end(),cmp);
int ans=max(0,x-2);
for(auto it:d)
{
//printf("%d ans:%d\n",it,ans);
if(it==1) continue;
if(it==2)
{
ans++;
continue;
}
int cnt=(it-1)/2,judge=it%2;
if(y>=cnt)
{
ans+=cnt;
ans+=cnt;
y-=cnt;
if(!judge) ans++;
}
else
{
ans+=y;
ans+=y;
y=0;
}
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
标签:cnt,Version,int,Hard,long,Birthday,ans
From: https://www.cnblogs.com/pure4knowledge/p/18311334