12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include <iostream>
- #include <algorithm>
- using namespace std;
- struct Box {
- int Ai;
- int Bi;
- };
- bool compare(Box a, Box b) {
- return a.Ai-a.Bi < b.Ai - b.Bi;
- }
- bool judge(int V, int N, Box *boxes) {
- sort(boxes, boxes + N, compare);
- for (int i = 0; i < N; i++) {
- if (boxes[i].Bi > V || boxes[i].Ai > V) {
- return false;
- }
- V -= boxes[i].Ai;
- }
- return true;
- }
- int main() {
- int T, V, N;
- Box *boxes;
- while (cin >> T) {
- for (int i = 0; i < T; i++) {
- cin >> V >> N;
- boxes = new Box[N];
- for (int j = 0; j < N; j++) {
- Box box;
- cin >> box.Ai >> box.Bi;
- boxes[j] = box;
- }
- cout << (judge(V, N, boxes) ? "Yes" : "No") << endl;
- free(boxes);
- }
- }
- return 0;
- }
|