#include using namespace std; typedef long long ll; ll a[2100],b[2100],s[2100]; int main(){ int test; scanf("%d", &test); while(test--){ int n; scanf("%d",&n); for(int i=0;i tasks; for(int i=n-1;i>=0;i--){ tasks.insert(a[i]); ll cost=b[i]; while(cost>0&&tasks.size()>0){ auto iter=tasks.begin(); ll val=*iter; tasks.erase(iter); ll use=min(cost,val); val-=use; cost-=use; if(val==0){ ans++; //printf("at %d cost %lld\n",i,cost); } else tasks.insert(val); } } printf("%d\n",ans); } }