孤独的倔强 @ 2019-08-08 15:04:43
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,g,sum;
struct asd
{
int a,b;
};
asd e[5005];
bool cnp(asd s,asd v)
{
return s.b<v.b;
}
int main()
{
cin>>a>>b>>c>>d;
g=c+d;
for(int i=0;i<a;i++)
{
cin>>e[i].a>>e[i].b;
}
sort(e,e+a,cnp);
for(int i=0;i<a;i++)
{
if(e[i].a<=g&&(b-e[i].b)>=0)
{
sum++;
b-=e[i].b;
}
}
cout<<sum;
return 0;
}
by pidan @ 2019-08-08 15:07:05
#include<bits/stdc++.h>
using namespace std;
long x[5001],n,a,b,s,y[5001],k=0;
int main(){
cin>>n>>s;
cin>>a>>b;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
for(int i=n-1;i>=1;i--){
for(int j=0;j<i;j++){
if(y[j]>y[j+1]){
swap(y[j],y[j+1]);
swap(x[j],x[j+1]);
}
}
}
for(int i=1;i<=n;i++){
if(x[i]<=a+b&&y[i]<=s){
k++;
s-=y[i];
}
}
cout<<k;
return 0;
}```
拿去不谢
by pidan @ 2019-08-08 15:08:06
话说那个函数应该叫cmp
by pidan @ 2019-08-08 15:10:18
不开longlong见祖宗
by 孤独的倔强 @ 2019-08-08 15:12:32
呵呵呵cmp打成cnp主要是键盘按键错位了