Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- struct Guest{
- int comes;
- int goes;
- int index;
- };
- struct comeComparator{
- bool operator()(Guest g1, Guest g2) const{
- return g1.comes > g2.comes;
- }
- };
- struct goComparator{
- bool operator()(Guest g1, Guest g2) const{
- return g1.goes > g2.goes;
- }
- };
- int main() {
- int n, a, b, t;
- priority_queue<Guest, vector<Guest>, comeComparator> expect;
- priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> there; //goes, chair
- priority_queue<int, vector<int>, greater<int>> chairs;
- cin >> n;
- for(int i = 0; i < n; i++){
- cin >> a >> b;
- expect.push({a, b, i});
- chairs.push(i);
- }
- int currTime = 0;
- cin >> t;
- while(!expect.empty()){
- while(expect.top().comes <= currTime){
- if(expect.top().index == t){
- cout << chairs.top();
- return 0;
- }
- there.push({expect.top().goes, chairs.top()});
- chairs.pop();
- expect.pop();
- }
- while(!there.empty() && there.top().first <= currTime){
- chairs.push(there.top().second);
- there.pop();
- }
- if(!expect.empty()){
- currTime = expect.top().comes;
- if(!there.empty())
- currTime = min(currTime, there.top().first);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment