1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <iostream>
- using namespace std;
- struct Box {
- int Ai;
- int Bi;
- };
- bool judge(int V, int maxAi, int maxBi, int allAi) {
- if (maxAi > maxBi){
- return false;
- }
- if (allAi > V){
- return false;
- }
- if(maxBi > V){
- return false;
- }
- return true;
- }
- int main() {
- int T, V, N;
- Box *boxes;
- while (cin >> T) {
- for (int i = 0; i < T; i++) {
- cin >> V >> N;
- int maxAi = 0, maxBi = 0;
- int allAi = 0;
- boxes = new Box[N];
- for (int j = 0; j < N; j++) {
- Box box;
- cin >> box.Ai >> box.Bi;
- if (box.Ai > maxAi) {
- maxAi = box.Ai;
- }
- if (box.Bi > maxBi) {
- maxBi = box.Bi;
- }
- allAi += box.Ai;
- boxes[j] = box;
- }
- cout << (judge(V, maxAi, maxBi, allAi) ? "YES" : "NO") << endl;
- free(boxes);
- }
- }
- return 0;
- }
|