ninininininini @ 2018-08-02 10:18:10
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,s,a,b,x[1005],y[1005],c,sum=0;
cin>>n>>s;
cin>>a>>b;
c=a+b;
for(int i=1; i<=n; i++) {
cin>>x[i]>>y[i];
}
for(int i=1; i<=n; i++) {
if(c>=x[i]&&s>0) sum++,s-=y[i];
if(c<x[i]);
if(s<=0) continue;
}
cout<<sum;
return 0;
}
by skiy_gyx @ 2018-08-02 10:48:39
你什么意思,是要代码吗
by skiy_gyx @ 2018-08-02 10:48:55
#include<bits/stdc++.h>
using namespace std;
int h[10010],v[10010];
int main(){
int n,s,a,b;
cin>>n>>s>>a>>b;
for(int i=1;i<=n;i++){
cin>>h[i]>>v[i];
}
for(int i=1;i<n;i++){
for(int j=1;j<=n-i;j++){
if(v[j]>v[j+1]){
swap(h[j],h[j+1]);
swap(v[j],v[j+1]);
}
}
}
int t=0;
for(int i=1;i<=n;i++){
if(s>v[i]){
if(a+b>=h[i]){
t++;
s-=v[i];
}
}else{
break;
}
}
cout<<t<<endl;
return 0;
}
by skiy_gyx @ 2018-08-02 10:49:16
用个冒泡就解决了