四大文化赛道完整展开
02-solution/src/cpp/main.cpp
main.cpp
站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。
文件类型.cpp
10-cases/s3-jh-06-market-calendar/02-solution/src/cpp/main.cpp
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, days_total;
if (!(cin >> n >> days_total)) {
return 0;
}
vector<int> diff(days_total + 3, 0);
for (int i = 0; i < n; ++i) {
int left, right;
cin >> left >> right;
++diff[left];
--diff[right + 1];
}
int active = 0;
int max_open = -1;
int first_peak = 0;
vector<pair<int, int>> merged;
int start = -1;
for (int day = 1; day <= days_total; ++day) {
active += diff[day];
if (active > max_open) {
max_open = active;
first_peak = day;
}
if (active > 0 && start == -1) {
start = day;
}
if (active == 0 && start != -1) {
merged.push_back({start, day - 1});
start = -1;
}
}
if (start != -1) {
merged.push_back({start, days_total});
}
cout << "max_open=" << max_open << "\n";
cout << "first_peak_day=" << first_peak << "\n";
cout << "merged=";
if (merged.empty()) {
cout << "NONE";
} else {
for (size_t i = 0; i < merged.size(); ++i) {
if (i) {
cout << '|';
}
cout << merged[i].first << '-' << merged[i].second;
}
}
cout << "\n";
return 0;
}