c++为什么是40分啊??
查看原帖
c++为什么是40分啊??
1457093
WATLERE楼主2024/11/20 09:38
#include <iostream>
#include <algorithm>
#define int long long

using namespace std;

int n, h[10001], b, height;

signed main()
{
	cin >> n >> b;
	
	for (int i = 0;i < n;i ++)
		cin >> h[i];
	
	sort(h, h+n, greater<int>());
	
	int cnt = 0;
	height = 0;
	for (int i = 0;i < n;i ++)
	{
		cnt ++;
		height += h[i];
		if (height >= b) break;
	}
	
	cout << cnt;
}
2024/11/20 09:38
加载中...