online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <algorithm> #include <iostream> #include <vector> using std::endl; using std::pair; using std::vector; bool ascSort(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.second < b.second; } vector<long long> optimal_points(vector<pair<long long, long long>> &segments) { vector<long long> points; long long n = segments.size(); long long count = 0; while (n != 0) { auto it1 = segments.begin(); // ---------- changed here long long firstNum = segments[0].second; for (long long i = 1; i < n; i++) { if ((firstNum <= segments[i].second) && (firstNum >= segments[i].first)) { std::cout << "YAYY" << endl; } else { points.push_back(firstNum); segments.erase(it1, it1 + (i - 1)); break; } } count = count + 1; } std::cout << count << endl; return points; } int main() { long long n; std::cin >> n; vector<long long> first; vector<long long> second; for (long long i = 0; i < n; i++) std::cin >> first[i] >> second[i]; vector<pair<long long, long long>> segments; for (long long i = 0; i < n; i++) segments.push_back({first[i], second[i]}); std::sort(segments.begin(), segments.end(), ascSort); vector<long long> points = optimal_points(segments); std::cout << points.size() << "\n"; for (size_t i = 0; i < points.size(); ++i) { std::cout << points[i] << " "; } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue