從第6測資點之後都是RE
記憶體區段錯誤! Segmentation fault (core dumped)
前5個正常AC 不清楚是哪裏有問
#include <iostream>
using namespace std;
int main(){
int event , full , evention[1000];
while(cin>>event>>full)
{
int l ;
long long int sum = 0 , max = 1;
//讀取飽足感
for(l=0;l<event;l++)
{
cin>>evention[l];
sum+=evention[l];
if(max<evention[l])
{
max = evention[l];
}
}
//排列
int i , j ;
for(i=1;i<event;i++)
{
for(j=0;j<event-1;j++)
{
if(evention[j+1] > evention[j])
{
int u ;
u = evention[j+1];
evention[j+1] = evention[j];
evention[j] = u;
}
}
}
if(sum < full) //吃不飽
{
cout<<"OAQ"<<endl;
}else
{
int k , ans;
long long int sum2 = 0 ;
for(k=0;k<event;k++)
{
sum2+=evention[k];
if(sum2 >= full)
{
ans = k+1 ;
break;
}
}
cout<<ans<<endl;
}
}
return 0;
}