大牛们为什么cmp中return 1;会一堆TLE+一个WA,但是换成return 1;后就AC了
这俩不一样吗,求助有什么区别 谢谢谢谢
#include <bits/stdc++.h>
using namespace std;
int x[20005];
bool cmp(int a,int b){
return a>b;
}
int main(){
int a,b;
scanf("%d %d",&a,&b);
for(int i=0;i<a;i++){
int p;
scanf("%d",&p);
x[i]=p;
}
sort(x,x+a,cmp);
int sum=0;
int t=0;
while(sum<b){
sum+=x[t];
t++;
}
printf("%d",t);
}