脑袋转不过来了为啥要加一才能过捏?
查看原帖
脑袋转不过来了为啥要加一才能过捏?
790685
bluetored楼主2022/11/4 22:38

大佬们请看最后几行break前的那个输出,为啥我加一才能过?

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int crow[20001];
	unsigned long long high,total=0;
	cin >> n>>high;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &crow[i]);
	}
	sort(crow + 1, crow + n + 1);
	for (int i = n; i >= 1; i--)
	{
		total += crow[i];
		if (total >= high) {
			cout << n+1 - i;
			break;
		}
	}
	return 0;
}
2022/11/4 22:38
加载中...