为什么只有第一个AC,其他都是RE,数组大小也没超得太大呀?
查看原帖
为什么只有第一个AC,其他都是RE,数组大小也没超得太大呀?
1371164
ljk13579楼主2024/7/31 22:13
#include<bits/stdc++.h>
using namespace std;
int n,t;
struct jin{
	int m,v;
	double xjb;
	void read(){
		cin >> m >> v;
		xjb=v/m*1.00;
	}
};
bool cmp(jin x,jin y){
	if(x.xjb>=y.xjb){
		return true;
	}else{
		return false;
	}
}
jin a[105];
int main(){
	cin >> n >> t;
	for(int i=1;i<=n;i++){
		a[i].read();
	}
	sort(a+1,a+n+1,cmp);
	int cnt1=1,cnt2=0;
	double cnt3=0;	
	while(cnt2<t&&cnt1<=n){
		if(cnt2+a[cnt1].m>t){
			cnt3 += (t-cnt2)*a[cnt1].xjb;
			break;
		}else{
			cnt3 += a[cnt1].v*1.00;
			cnt2 += a[cnt1].m;
			cnt1++;
		}
	}
	cout<<fixed<<setprecision(2)<<cnt3<<endl;
	return 0;
}
2024/7/31 22:13
加载中...