bbggxggg @ 2022-11-28 19:41:03
#include<bits/stdc++.h>
using namespace std;
long long power[1000001],high[10000001];
int main()
{
long long n,i,a,b,s,w,ss=0;
cin>>n>>s;
cin>>a>>b;
for(i=1;i<=n;i++){
cin>>high[i]>>power[i];
}
w=a+b;
sort(power+1,power+1+n);
for(i=1;i<=n;i++){
if(s<=0){
break;
}
else if(high[i]<=w&&s>0&&s>=power[i]){
ss++;
}
s=s-power[i];
}
cout<<ss;
return 0;
}
by Hxbbd_YCY @ 2022-11-28 20:12:33
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+5;
struct Point
{
int r;
int d;
}c[maxn];
int cmp(Point a1,Point a2)
{
return a1.d<a2.d;
}
int main()
{
int n,a,b,s,sum=0;
cin>>n>>s>>a>>b;
for(int i=0;i<n;i++)
{
cin>>c[i].r>>c[i].d;
}
sort(c,c+n,cmp);
for(int i=0;i<n;i++)
{
if(c[i].r<=a+b&&c[i].d<=s)
{
s-=c[i].d;
sum++;
}
else if(s<=0) break;
else continue;
}
cout<<sum<<endl;
return 0;
}
by bbggxggg @ 2022-11-28 20:48:55
@ycy2022 本人不会函数。。。。。
by Hxbbd_YCY @ 2022-11-28 21:58:36
啊这
by Hxbbd_YCY @ 2022-11-28 22:08:16
排序你只排了power,需要把power和high绑定在一起
by Hxbbd_YCY @ 2022-11-28 22:17:17
建议把sort改为冒泡,power和high一起排
by _Coffice_ @ 2022-12-09 17:42:22
结果一样,#3#5 WA
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
struct apple{
long long x,y;
};
apple all[10000];
long long n,s,h;
void input(){
cin >> n >> s;
long long a,b;
cin >> a >> b;
h = a+b;
for(long long i = 0;i<n;i++)cin >> all[i].x >> all[i].y;
return;
}
void bsort(apple a[]){
for(long long i = n-1;i>0;i--){
for(long long j = 0;j<i;j++){
if(a[j].y > a[j+1].y) swap(a[j],a[j+1]);
}
}
}
int main(){
input();
apple can[n+1];
long long len = 0;
for(long long i = 0;i<n;i++){
if(all[i].x <= h){
can[len] = all[i];
len++;
}
}
bsort(can);
n = len;
long long sum = 0,sums = 0;
for(long long i = 0;i<n;i++){
if(can[i].y+sums < s){
sums += can[i].y;
sum++;
}
}
cout << sum;
return 0;
}