首页 > 其他分享 >题解:Codeforces Round 964 (Div. 4) C

题解:Codeforces Round 964 (Div. 4) C

时间:2024-08-07 16:21:08浏览次数:7  
标签:964 10 Alex 小明 题解 leq time test Div

C. Showering

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output


As a computer science student, Alex faces a hard challenge — showering. He tries to shower daily, but despite his best efforts there are always challenges. He takes \(s\) minutes to shower and a day only has \(m\) minutes!

He already has \(n\) tasks planned for the day. Task \(i\) is represented as an interval \((l_i\), \(r_i)\), which means that Alex is busy and can not take a shower in that time interval (at any point in time strictly between \(l_i\) and \(r_i\)). No two tasks overlap.

Given all \(n\) time intervals, will Alex be able to shower that day? In other words, will Alex have a free time interval of length at least \(s\)?

In the first test case, Alex can shower for the first \(3\) minutes of the day and not miss any of the tasks.

Input

The first line contains a single integer \(t\) (\(1 \leq t \leq 10^4\)) — the number of test cases.

The first line of each test case contains three integers \(n\), \(s\), and \(m\) (\(1 \leq n \leq 2 \cdot 10^5\); \(1 \leq s, m \leq 10^9\)) — the number of time intervals Alex already has planned, the amount of time Alex takes to take a shower, and the amount of minutes a day has.

Then \(n\) lines follow, the \(i\)-th of which contains two integers \(l_i\) and \(r_i\) (\(0 \leq l_i \lt r_i \leq m\)) — the time interval of the \(i\)-th task. No two tasks overlap.

Additional constraint on the input: \(l_i \gt r_{i-1}\) for every \(i \gt 1\).

The sum of \(n\) over all test cases does not exceed \(2 \cdot 10^5\).

Output

For each test case output "YES" (without quotes) if Alex can take a shower for that given test case, and "NO" (also without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes", and "Yes" will be recognized as a positive response).

题意

小明每天很忙,但是还要洗澡
小明每天只有 \(m\) 小时可以分配
小明每天洗澡需要连续的 \(s\) 小时
小明每天要完成 \(n\) 个任务
小明做的第 \(i\) 个任务需要再 \(l_1\) 和 \(r_1\) 这个时间区间完成
小明的每个任务时间不会重叠
问:小明有空洗澡吗

Example

Input

4
3 3 10
3 5
6 8
9 10
3 3 10
1 2
3 5
6 7
3 3 10
1 2
3 5
6 8
3 4 10
1 2
6 7
8 9

Output

YES
YES
NO
YES

题解

s和以下时间间隔比较

  • 最前面的任务和第0小时之间的空闲时间
  • 一天最后的的第m小时和最后一个任务结束之间的空闲时间
  • 每个任务之间的空闲时间

只要比任意一个时间间隔小
小明就能洗澡了

代码

#include <bits/stdc++.h>
#define int unsigned long long
#define INF 0x3f3f3f3f
#define all(x) x.begin(),x.end()

int t = 1;

void solve() {
    int n,s,m;
    std::cin >> n >> s >> m;
    std::vector<std::pair<int,int> > a(n);
    for(int i = 0 ; i < n; i ++) {
        std::cin >> a[i].first >> a[i].second;
    }
    std::sort(all(a));
    for(int i = 0 ; i < n ; i ++) {
        int kong;
        if(!i) kong = a[i].first - 0;
        else kong = a[i].first - a[i-1].second;

        if(kong >= s) {
            std::cout << "YES\n";
            return;
        }
    }
    if(m - a[n-1].second >= s) std::cout << "YES\n";
    else std::cout << "NO\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    std::cin >> t;
    while(t--) solve();
    return 0;
}

标签:964,10,Alex,小明,题解,leq,time,test,Div
From: https://www.cnblogs.com/jiejiejiang2004/p/18347242

相关文章

  • CF1689C题解
    CF1689CInfectedTree题解怎么只有我这个蒟蒻不会DP啊。回归正题……简化题意给定一棵以$1$号节点为根的二叉树,总节点个数为$n$。现在$1$号节点感染了病毒,你在这一回合里可以使病毒所在节点的一个儿子不被感染,而病毒会感染一个不受保护的儿子。询问最多可以有多少不......
  • 烧烤 题解
    题目id:11063题目描述\(Snuke\)有一个烧烤聚会。聚会上,他将制作\(N\)份串烧。$\\\\\\\$一份串烧他有\(2N\)根烤肉钎子,它们都将用于制作串烧。第i个烤肉钎子的长度为Li。此外,他有无限供应的原料。他将原料串在两根烤肉钎子上做成一份串烧。一份串烧可串起的原料的最大......
  • 信创系统问题解决笔记
    本文记述解决信创系统显示问题过程经历,描述遇到的各种问题以及解决方法。问题描述测试反馈,在信创系统上,部分界面字体显示异常,表现为内容越界、文字区域显示为小空格,如下图所示:初步分析是字体原因,具体情况需要更进一步分析。问题复现测试团队的信创测试环境有UOS和Kylin两个......
  • CF1999题解
    题目链接CF1999A解题思路模拟。没了。参考代码/*Tips:你数组开小了吗?你MLE了吗?你觉得是贪心,是不是该想想dp?一个小时没调出来,是不是该考虑换题?打cf不要用umap!!!记住,rating是身外之物。该冲正解时冲正解!Problem:算法:思路:*/#include<bits/stdc++.h>usin......
  • Codeforces Round 964 (Div. 4)
    比赛链接:CodeforcesRound964(Div.4)A思路    水题代码#include<iostream>usingnamespacestd;#definelllonglonginlineintread(void){intx=0,f=1;charch=getchar();while(ch<'0'||ch>'9'){......
  • 2024.8.7 模拟赛题解
    T1过于简单,不必阐述。T2给定一个仅包含\(A\)和\(P\)的字符串,每次操作可以删除相邻的\(AP\)或者\(PP\),问字符串最后的最小长度。$Sol:$为求最值问题,考虑贪心。先给出考场做法。发现若干的\(P\)是一定能合并掉的,于是贪心策略,就是如何最小化\(A\)的个数。对于每个......
  • 题解:Codeforces Round 964 (Div. 4) A
    A.A+BAgain?timelimitpertest:1secondmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputGivenatwo-digitpositiveinteger\(n\),findthesumofitsdigits.InputThefirstlinecontainsaninteger\(t\)(\(1......
  • 【题解】Solution Set - NOIP2024集训Day1 数据结构
    【题解】SolutionSet-NOIP2024集训Day1数据结构https://www.becoder.com.cn/contest/5429「CF1428F」FruitSequences线段树是可以维护区间最长子段的1。记固定右端点在\(i\),的答案为\(f_i\)。那么:\(a_i=0\),\(f_i=f_{i-1}\);\(a_i=1\),打一个单调栈维护所有的最长子......
  • 题解:P10543 [THUPC 2024 决赛] 黑白
    好题。题意\(n\timesm\)的网格图初始每个格子有黑有白,两人轮流操作,每次选择一个白格染黑。操作后不能存在一条\((1,1)\)到\((n,m)\)的路径,否则本次操作者输,另一人赢。思路首先判断是否一上来就输了。易发现到最后一定会操作到只剩一条道路,设路径长度为\(s\),那么\(s\)......
  • 题解:UVA11181 条件概率 Probability|Given
    主要思路:概率期望。首先可以发现\(n\)的数据极小。然后我们设\(a\)为为每个人买东西的情况,\(b\)为当有\(b\)个人去时的情况。大家都应该知道条件概率式子为\(P(a|b)=\frac{P(ab)}{P(b)}\)。然后暴力搜索\(P(ab)\)和\(P(b)\)。其实这道题有复杂度更低的dp做法,但......