Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include "optimization.h"
- using namespace std;
- int main() {
- int m = readInt();
- vector<pair<int, int>> arr, ans;
- while(true) {
- int a = readInt(), b = readInt();
- if(a == 0 && b == 0) {
- break;
- }
- if(b > 0) {
- arr.emplace_back(a, b);
- }
- }
- sort(arr.begin(), arr.end());
- int curR = 0;
- int maxR = -1;
- for (int i = 0; i < arr.size(); i++) {
- if(arr[i].first > curR) {
- if(maxR == -1 || arr[maxR].second < arr[i].first) {
- writeWord("No solution\n");
- return 0;
- } else {
- ans.push_back(arr[maxR]);
- curR = arr[maxR].second;
- maxR = -1;
- if(curR >= m) {
- break;
- }
- }
- }
- if(maxR == -1 || arr[i].second > arr[maxR].second) {
- maxR = i;
- }
- }
- if(curR < m) {
- if(maxR == -1 || arr[maxR].second < m) {
- writeWord("No solution\n");
- return 0;
- }
- ans.push_back(arr[maxR]);
- }
- writeInt(ans.size(), '\n');
- for(auto p : ans) {
- writeInt(p.first, ' ');
- writeInt(p.second, '\n');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment