Codeforces Round #811 (Div. 3) A Everyone Loves to Sleep

大炮打蚊子。两个优先队列,存前后时间。如果后面有就取后面最小,没有后面就取前面最小。

实际上不需要优先队列

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef unsigned long long ULL;
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        priority_queue<int,vector<int>, greater<int>> q_back;
        priority_queue<int,vector<int>, greater<int>> q_front;
        int n, h, m;
        cin >> n >> h >> m;
        int ans = 0;
        while (n--)
        {
            int a, b;
            cin >> a >> b;
            if(a * 60 + b >= h * 60 + m) q_back.push(a * 60 + b);
            else q_front.push(a * 60 + b);
        }
        if(q_back.size())
        {
            ans = q_back.top();
            ans = ans - (h * 60 + m);
        } 
        else 
        {
            ans = q_front.top();
            ans = 24 * 60 - (h * 60 + m) + ans;
        }
        cout << ans / 60 << ' ' << ans % 60 << endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值