jiejiejiang2004

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

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 (li, ri), which means that Alex is busy and can not take a shower in that time interval (at any point in time strictly between li and ri). 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 (1t104) — the number of test cases.

The first line of each test case contains three integers n, s, and m (1n2105; 1s,m109) — 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 li and ri (0li<rim) — the time interval of the i-th task. No two tasks overlap.

Additional constraint on the input: li>ri1 for every i>1.

The sum of n over all test cases does not exceed 2105.

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 个任务需要再 l1r1 这个时间区间完成
小明的每个任务时间不会重叠
问:小明有空洗澡吗

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;
}

posted on   Jiejiejiang  阅读(60)  评论(0编辑  收藏  举报

编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」

导航

统计信息

点击右上角即可分享
微信分享提示