为什么40分啊?

@ superhandsomejack 2017-07-17 21:36
#include<bits/stdc++.h>
using namespace std;
int a[5005],b[5005];
int main()
{
    int j,i,sum=0,x,y,n,l;
    cin>>x>>n>>y>>l;
    l=l+y; 
    for (i=1;i<=x;i++){cin>>a[i]>>b[i];}
    for (i=1;i<=x;i++)
      for (j=1;j<=x-i;j++)
      if (b[i]>b[i+1]){b[0]=b[i];b[i]=b[i+1];b[i+1]=b[0];
      a[0]=a[i];a[i]=a[i+1];a[i+1]=a[0];}
    for (i=1;i<=x;i++)
    {if (a[i]<=l){sum++;n-=b[i];}
    if (n<=0)break;}
    cout<<sum;
    return 0;
}
@ Administrator2004 2017-07-17 22:35 回复
#include<iostream>
using namespace std;
int xi[5001],yi[5001];
int main()
{
int n,s,a,b,app=0;
cin>>n>>s>>a>>b;
a+=b;
for(int i=0;i<n;i++) cin>>xi[i]>>yi[i];
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(yi[j]<yi[i])
{
swap(xi[j],xi[i]);
swap(yi[j],yi[i]);
}
}
}
for(int i=0;i<n;i++)
{
if(s<=0) break;
if(xi[i]<=a&&s-yi[i]>=0)
{
app++;
s-=yi[i];
}
}
cout<<app;
return 0;
}