RT,被橙题卡了一天的孩子AC不了这道题......错了#31,想知道是算法本身有漏洞还是有些细节没注意到.
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
int n,t,ans,tot,ans1;
template<typename T>inline void read(T& x)
{
x=0;char c=getchar();bool f=0;
while(!isdigit(c)&&c!='-') c=getchar();
if(c=='-') f=1,c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
if(f) x=-x;
}
struct node
{
int a,b;
}pro[N];
inline bool cmp(node a,node b){
if(a.b<b.b||(a.b==b.b&&a.a<b.a)) return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
read(n);
for(int i=1;i<=n;i++)
{
int x,y;
read(x);read(y);
if(x<=y){
pro[++tot].a=x;
pro[tot].b=y;
}
}
sort(pro+1,pro+tot+1,cmp);
for(int i=1;i<=tot;i++)//浪费评测时间
{
int now=i;
t=0;
int maxi=0;
while(now<=tot)
{
if(t+pro[now].a>pro[now].b){
now++;
continue;
}
t+=pro[now].a;
maxi++;
now++;
}
ans=max(ans,maxi);
}
cout<<ans<<"\n";
return 0;
}