#include<iostream> #include<queue> #include<algorithm> usingnamespace std; constint MAX = 8e5+10; int T; int N; structwork { int x, y; work(int a=0, int b=0) { x = a; y = b; } }; work works[MAX]; boolcmp(work a, work b) { if (a.y == b.y) return a.x < b.x; return a.y < b.y; } intmain() { int time; cin >> T; while (T--) { time = 0; priority_queue<int>pq; cin >> N; for (int i = 0; i < N; i++) { cin >> works[i].x >> works[i].y; } sort(works, works + N, cmp); for (int i = 0; i < N; i++) { if (time + works[i].x <= works[i].y) { pq.push(works[i].x); time += works[i].x; } elseif (!pq.empty()) { if (pq.top() >= works[i].x) { time = time - pq.top() + works[i].x; pq.pop(); pq.push(works[i].x); } } } cout << pq.size() << endl; if (T != 0) cout << endl; } }