Объяснение:
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N, A, B;
cin >> N;
vector < vector <int>> IO;
int lastDay = 0;
for (int i = 0; i < N; i++) {
cin >> A >> B;
IO.push_back(vector<int>());
IO[i].push_back(A);
IO[i].push_back(B);
IO[i].push_back(i);
}
sort(IO.begin(), IO.end());
for (int i = 0; i < N; i++)
{
if (lastDay >= IO[i][1]) {
IO[i][0] = -1;
IO[i][1] = -1;
else {
if (lastDay < IO[i][0]) {
lastDay = IO[i][1];
else if (lastDay >= IO[i][0]) {
IO[i][0] = lastDay+1;
for (int j = 0; j < N; j++) {
if (IO[j][2] == i) {
cout << IO[j][0] << " " << IO[j][1] << endl;
break;
return 0;
Объяснение:
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N, A, B;
cin >> N;
vector < vector <int>> IO;
int lastDay = 0;
for (int i = 0; i < N; i++) {
cin >> A >> B;
IO.push_back(vector<int>());
IO[i].push_back(A);
IO[i].push_back(B);
IO[i].push_back(i);
}
sort(IO.begin(), IO.end());
for (int i = 0; i < N; i++)
{
if (lastDay >= IO[i][1]) {
IO[i][0] = -1;
IO[i][1] = -1;
}
else {
if (lastDay < IO[i][0]) {
lastDay = IO[i][1];
}
else if (lastDay >= IO[i][0]) {
IO[i][0] = lastDay+1;
lastDay = IO[i][1];
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (IO[j][2] == i) {
cout << IO[j][0] << " " << IO[j][1] << endl;
break;
}
}
}
return 0;
}