

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Event {
int start, end;
bool operator<(const Event& other) const {
return start < other.start || (start == other.start && end > other.end);
}
};
int main() {
int N;
cin >> N;
vector<Event> events(N);
for (int i = 0; i < N; ++i) {
cin >> events[i].start >> events[i].end;
}
sort(events.begin(), events.end());
int count = 0;
int max_end = -1;
for (const auto& event : events) {
if (event.end <= max_end) {
++count;
} else {
max_end = event.end;
}
}
cout << count << endl;
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin