比赛 |
贪心题目练习 |
评测结果 |
AWWWWWWWWW |
题目名称 |
畜栏预定 |
最终得分 |
10 |
用户昵称 |
OTTF |
运行时间 |
0.346 s |
代码语言 |
C++ |
内存使用 |
3.51 MiB |
提交时间 |
2025-03-22 11:11:13 |
显示代码纯文本
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int n;
pair<int, int> num[51145];
priority_queue<pair<int, int> > pq;
int res;
int pos[51145];
int main () {
freopen ("stallreservation.in", "r", stdin);
freopen ("stallreservation.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> num[i].first >> num[i].second;
}
sort (num + 1, num + 1 + n);
for (int i = 1; i <= n; i++) {
if (pq.empty() || -pq.top().first > num[i].first) {
res++;
pq.push(make_pair (-num[i].second, res));
pos[i] = res;
}
else {
int id = pq.top().second;
pq.pop();
pq.push(make_pair (-num[i].second, id));
pos[i] = id;
}
}
cout << res << endl;
for (int i = 1; i <= n; i++) {
cout << pos[i] << endl;
}
return 0;
}