|
@@ -9,16 +9,13 @@ struct Box {
|
|
|
};
|
|
|
|
|
|
bool compare(Box a, Box b) {
|
|
|
- return a.Bi > b.Bi;
|
|
|
+ return a.Ai-a.Bi < b.Ai - b.Bi;
|
|
|
}
|
|
|
|
|
|
-bool judge(int V, int N, int record, int maxAi, int maxBi, int allAi, Box *boxes) {
|
|
|
- if (allAi > V || maxAi > V || maxBi > V) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+bool judge(int V, int N, Box *boxes) {
|
|
|
sort(boxes, boxes + N, compare);
|
|
|
- for (int i = 0; i < record; i++) {
|
|
|
- if (boxes[i].Bi > V) {
|
|
|
+ for (int i = 0; i < N; i++) {
|
|
|
+ if (boxes[i].Bi > V || boxes[i].Ai > V) {
|
|
|
return false;
|
|
|
}
|
|
|
V -= boxes[i].Ai;
|
|
@@ -32,21 +29,13 @@ int main() {
|
|
|
while (cin >> T) {
|
|
|
for (int i = 0; i < T; i++) {
|
|
|
cin >> V >> N;
|
|
|
-
|
|
|
- int maxAi = 0, maxBi = 0;
|
|
|
- int allAi = 0;
|
|
|
- int record = 0;
|
|
|
boxes = new Box[N];
|
|
|
for (int j = 0; j < N; j++) {
|
|
|
Box box;
|
|
|
cin >> box.Ai >> box.Bi;
|
|
|
- allAi += box.Ai;
|
|
|
- if (box.Bi > box.Ai) {
|
|
|
- boxes[j] = box;
|
|
|
- record++;
|
|
|
- }
|
|
|
+ boxes[j] = box;
|
|
|
}
|
|
|
- cout << (judge(V, N, record, maxAi, maxBi, allAi, boxes) ? "Yes" : "No") << endl;
|
|
|
+ cout << (judge(V, N, boxes) ? "Yes" : "No") << endl;
|
|
|
free(boxes);
|
|
|
}
|
|
|
}
|