求助
查看原帖
求助
701948
fee600楼主2022/7/18 09:49

第一个测试点运行错误

#include <bits/stdc++.h>
using namespace std;
struct P2240 {
	unsigned long long m, u;
	double j;
} a[100001];
bool cmp(P2240 x, P2240 y) {
	return x.j > y.j;
}
int main() {
	unsigned long long n, t;
	double s = 0;
	cin >> n >> t;
	if(n==0||t==0)
	{
		cout<<"0.00";
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i].m >> a[i].u;
		a[i].j = 1.0 * a[i].u / a[i].m;
	}
	sort(a + 1, a + n + 1, cmp);
	int i=1;
	while (t>0) {
		t--;
		/*
		cout<<i<<endl;
		cout<<t<<endl;*/
		if (a[i].m >= 1) {
			s += a[i].j;
			a[i].m--;
			//cout<<t<<' '<<a[i].m<<' '<<a[i].j<<' '<<s<<endl;
			continue;
		} else if (a[i].m == 0) {
			t++;
			i++;
			continue;
		} else if (i > n) {
			break;
		}
	}
	printf("%.2lf",s);
}
2022/7/18 09:49
加载中...