您的sort?应该是``sort(st+1,st+c+1)``才对吧
by Eason_AC @ 2019-08-02 15:38:41
还有您的数组要开到**10010**
by Eason_AC @ 2019-08-02 15:39:40
@[森森鸭](/space/show?uid=216176)
by Eason_AC @ 2019-08-02 15:39:45
@[Eason_AC](/space/show?uid=112917) 谢谢!!!!!
by 森森鸭 @ 2019-08-02 15:45:44
@[Eason_AC](/space/show?uid=112917) #4wa声一片,有点衰
```c
#include <bits/stdc++.h>
using namespace std;
int main()
{
int aps,sl,h1,h2,h;
cin>>aps>>sl>>h1>>h2;
h=h1+h2;
int st[10010];
int c=1,hs=0,ans=0;
for(int i=1;i<=aps;i++)
{
int a,b;
cin>>a>>b;
if(a<=h) st[c]=b,c++;
}
sort(st+1,st+c);
for(int i=1;i<=c-1;i++)
{
if(hs+st[i]<=sl)
{
hs+=st[i];
ans++;
}
else
{
cout<<ans;
break;
}
}
return 0;
}
```
by 森森鸭 @ 2019-08-02 15:48:39
你干脆看一下我的代码吧,你这个代码写的好像有点乱
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int m[10000],n,s,a,b,x,y,k,t=0,d,c,ans=0;
int main() {
cin>>n>>s>>a>>b;
for(int i=1; i<=n; i++) {
cin>>x>>y;
if(a+b>=x) {
m[++t]=y;
}
}
sort(m+1,m+t+1);
c=1;
while(s-m[c]>=0 &&c<=t) {
ans++;
s-=m[c];
c++;
}
cout<<ans;
return 0;
}
```
@[森森鸭](/space/show?uid=216176)
by Eason_AC @ 2019-08-02 15:51:48
@[森森鸭](/space/show?uid=216176) 下数据,~~特判~~「不要学我,这是不正当手段
by 本号停止使用 @ 2019-08-02 15:52:39
@[Eason_AC](/space/show?uid=112917) 好的谢谢啦!!?
by 森森鸭 @ 2019-08-02 15:52:53
@[卢禺佟666](/space/show?uid=93447) 嘻嘻嘻好的学到了,现在ac啦以后有不会的特判嘿嘿?
by 森森鸭 @ 2019-08-02 16:01:21
@[森森鸭](/space/show?uid=216176) emmm……
by 本号停止使用 @ 2019-08-02 16:03:10