Submission
Status:
Compilation Error
Score: 0
User: Punnawith
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.000 second
Submitted On: 2025-03-22 19:17:41
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<int>> book(n, vector<int>(2));
vector<int> bookList;
for(int i = 0; i < n; i++) {
for(int j = 0; j < 2; j++) {
cin >> book[i][j];
}
}
for(int i = 0; i < n; i++) {
int x1 = book[i][0];
int x2 = book[i][1];
while(x1 < x2) {
bookList.push_back(x1);
x1++;
}
}
int median;
sort(bookList.begin(), bookList.end());
int lastIndex = bookList.size();
if(lastIndex % 2 == 0) {
int mid = lastIndex / 2;
median = (bookList[mid - 1] + bookList[mid]) / 2;
} else {
int mid = (lastIndex - 1) / 2;
median = bookList[mid1];
}
cout << median;
}