yuguoyu @ 2021-11-24 10:00:42
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define ll long long
#define MAXN 1000100
using namespace std;
int main()
{
long long a[5100],x,w,v,n,t,s[5100];
cin>>v>>n;
cin>>t>>x;
for(int i=0;i<v;i++)
cin>>a[i]>>s[i];
sort(s,s+v);
for(int i=0;i<v;i++)
{
if((x>=a[i]&&n>=s[i])||(x+t>=a[i]&&n>=s[i]))
{
n-=s[i];
w++;
}
}
cout<<w;
}
by Y2y7m @ 2021-11-24 12:48:04
#include <bits/stdc++.h>
using namespace std;
struct pg
{
int h,l;
}a[5010];
bool cmp(pg x,pg y)
{
return x.l<y.l;
}
int main()
{
int n,s;
int c,b;
cin>>n>>s;
cin>>c>>b;
int cnt=0;
for(int i=1;i<=n;i++)
{
cin>>a[i].h>>a[i].l;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
if(a[i].h<=c+b&&a[i].l<=s)
{
cnt++;
s-=a[i].l;
}
}
cout<<cnt
return 0;
}
自行解决吧
温馨提示:会ce
by Y2y7m @ 2021-11-24 12:49:40
@zhanan 你也可以试一试面向数据编程