Retrospective @ 2019-04-28 21:37:36
#include<bits/stdc++.h>
using namespace std;
long long n,s,k1,k2;
long long a,b,k;
struct stu
{
long long gd,ld;
} c[5005];
bool px1(stu x,stu y)
{
return x.gd<y.gd;
}
bool px2(stu x,stu y)
{
return x.ld<y.ld;
}
int main()
{
cin>>n>>s>>a>>b;
k=a+b;
for(int i=1;i<=n;i++)
cin>>c[i].gd>>c[i].ld;
sort(c+1,c+n+1,px1);
for(int i=1;i<=n;i++)
{
if(k>=c[i].gd && s>c[i].ld) {k1++,s-=c[i].ld;}
else break;
}
sort(c+1,c+n+1,px2);
for(int i=1;i<=n;i++)
{
if(k>=c[i].gd && s>c[i].ld) {k2++,s-=c[i].ld;}
else break;
}
if(k1>k2) cout<<k1;
else cout<<k2;
return 0;
}
by Skyjoy @ 2019-04-28 22:19:17
不知道,AC代码附上:
using namespace std;
int c[101];
int main(){
int n,s,h,a,b,i,cnt=0;
cin>>n>>s>>h>>i;h+=i;
for(i=1;i<=n;i++){
cin>>a>>b;
if(a<=h)c[b]++;
}
for(i=0;i<=100&&s>=0;i++){
while(c[i]){
s-=i;
cnt++;
c[i]--;
if(s<0){
cnt--;
break;
}
}
}
cout<<cnt;
return 0;
}
by TakeMe @ 2019-04-28 22:20:03
@铁甲玄武
using namespace std; int xi[100000],yi[100000]; int tx,ty; int main() { int n,s; int a,b; int i,j; int c; int ans=0; cin>>n>>s; cin>>a>>b; for(i=1; i<=n; i++) { cin>>xi[i]>>yi[i]; } c=a+b; for(i=1;i<=n;i++){ for(j=i+1;j<=n;j++){ if(yi[i]>yi[j]){ tx=xi[i],ty=yi[i]; xi[i]=xi[j],yi[i]=yi[j]; xi[j]=tx,yi[j]=ty; } } } for(i=1; i<=n; i++) { if(c>=xi[i]&&s>=yi[i]) { ans++; s-=yi[i]; } } cout<<ans; return 0; } 这是正解,可以复制下来看看
by qwaszx @ 2019-04-29 07:08:01
希更展?使MD