蒟蒻求助!0pts代码求调
查看原帖
蒟蒻求助!0pts代码求调
717006
Sleeping_Rain楼主2023/8/8 21:56
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,w[22],x[22],y[22],z[22],ans;
bool cmp(int l,int m)
{
	return l>m;
}
int main()
{
    cin>>a>>b>>c>>d;
    for(int i=1;i<=a;i++)
    {
    	cin>>w[i];
	}
	for(int i=1;i<=b;i++)
    {
    	cin>>x[i];
	}
	for(int i=1;i<=c;i++)
	{
		cin>>y[i];
	}
	for(int i=1;i<=d;i++)
    {
    	cin>>z[i];
	}	
	if(a==1) ans+=w[1];
	else
	{
		sort(w+1,w+a+1,cmp);
		int t=0;
		for(int i=1;i<=a;i++)
		{
			if(w[i]>t) 
			{
				t=w[i]-t;
				ans+=t; 
			}
			else t-=w[i];
		}
	}
	if(b==1) ans+=x[1];
	else
	{
		sort(x+1,x+b+1,cmp);
		int t=0;
		for(int i=1;i<=b;i++)
		{
			if(x[i]>t) 
			{
				t=x[i]-t;
				ans+=t; 
			}
			else t-=x[i];
		}
	}
	if(c==1) ans+=y[1];
	else
	{
		sort(y+1,y+c+1,cmp);
		int t=0;
		for(int i=1;i<=c;i++)
		{
			if(y[i]>t) 
			{
				t=y[i]-t;
				ans+=t; 
			}
			else t-=y[i];
		}
	}
	if(d==1) ans+=z[1];
	else
	{
		sort(z+1,z+d+1,cmp);
		int t=0;
		for(int i=1;i<=d;i++)
		{
			if(z[i]>t) 
			{
				t=z[i]-t;
				ans+=t; 
			}
			else t-=z[i];
		}
	}
   cout<<ans;
   return 0;
}

没有想明白出错原因,望各位大佬帮忙指点, (其实是懒得重写搜索)

2023/8/8 21:56
加载中...