悬关求助!
查看原帖
悬关求助!
1026751
Lawrenceling楼主2024/5/19 13:33

00 分WA,思路是贪心。

错误信息:

“Wrong Answer.wrong answer Too short on line 3.”

代码:

#include<bits/stdc++.h> 
using namespace std;
const int N=1e3+10;

long long n,k;
struct Node{
	long long a,b;
}t[N];

bool cmp(Node x,Node y)
{
	if( (x.b-x.a)==(y.b-y.a) )return x.b>y.b;
	else return (x.b-x.a)<(y.b-y.a);
}
int main()
{
	while(cin>>n>>k && n!=0 && k!=0)
	{
		for(int i=1;i<=n;++i)
		{
			scanf("%lld",&t[i].a);
		}
		for(int i=1;i<=n;++i)
		{
			scanf("%lld",&t[i].b);
		}
		if(n==k)
		{
			cout<<"100\n";
			continue;
		}
		sort(t+1,t+n+1,cmp);
		long double d=0,e=0;
		for(int i=1;i<=n-k;++i)
		{
			d+=t[i].a;
			e+=t[i].b;
		}
		cout<<round(d/e*100.00)<<'\n';
	}
	return 0;
} 
2024/5/19 13:33
加载中...