ABC C 求助
  • 板块学术版
  • 楼主Disjoint_cat
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/10/1 21:49
  • 上次更新2023/10/27 09:17:48
查看原帖
ABC C 求助
549499
Disjoint_cat楼主2022/10/1 21:49

为什么我的代码老是WA 1个点。。。。。。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=300005;
int n,a[N],s=1,t;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	//freopen("1.txt","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);a[n+1]=0;
	if(n==1&&a[1]>1)
	{
		puts("0");
		return 0;
	}
	int i;
	for(i=1;i<=N;i++)//读到VOL.i
	{
		if(a[s]==i)while(s<=n&&a[++s]==i)t++;
		else if(t>=2)t-=2;
		else if(t&&s<=n)n--,t--;
		else if(s+1<=n)n-=2;
		else break;
		a[n+1]=0;
		//cout<<s<<endl;
	}
	cout<<i-1;
	return 0;
}
2022/10/1 21:49
加载中...