当前位置: 首页 > news >正文

AtCoder Weekday Contest 0031 Beta题解(AWC 0031 Beta A-E)

D - Library Inventory Check

【题目来源】

AtCoder:D - Library Inventory Check

【题目描述】

Takahashi is working as a librarian and is in charge of a book inspection spanning \(N\) days.
高桥是一名图书馆员,负责一项为期 \(N\) 天的书籍检查工作。

This library has \(M\) books. To ensure that no deterioration or damage to books is overlooked, a standard has been established that each book \(j\) \((1 \leq j \leq M)\) must be inspected on at least \(R_j\) days out of the \(N\) days.
这个图书馆有 \(M\) 本书。为了确保不遗漏书籍的劣化或损坏,制定了一个标准:每本书 \(j\)\(1 \leq j \leq M\))在 \(N\) 天中至少需要被检查 \(R_j\) 天。

On the other hand, the maximum number of books that can be inspected on day \(i\) \((1 \leq i \leq N)\) is \(L_i\). Also, the same book cannot be inspected multiple times on the same day, but the same book can be inspected again on a different day.
另一方面,每天 \(i\)\(1 \leq i \leq N\))最多可以检查 \(L_i\) 本书。此外,同一本书在同一天不能被检查多次,但同一本书可以在不同日期再次检查。

Takahashi is free to decide which books to inspect on which days. Determine whether it is possible to create an inspection plan that satisfies the inspection requirements for all books.
高桥可以自由决定在哪天检查哪些书。判断是否有可能制定一个满足所有书籍检查要求的检查计划。

Specifically, determine whether there exists an inspection plan that satisfies all of the following conditions:
具体来说,判断是否存在一个满足以下所有条件的检查计划:

  • The number of books inspected on each day \(i\) is at most \(L_i\).
    每天 \(i\) 检查的书籍数量不超过 \(L_i\)
  • The same book is not inspected more than once on the same day.
    同一本书在同一天不被检查超过一次。
  • The total number of days each book \(j\) is inspected is at least \(R_j\).
    每本书 \(j\) 被检查的总天数至少为 \(R_j\)

【输入】

\(N\) \(M\)
\(L_1\) \(L_2\) \(\ldots\) \(L_N\)
\(R_1\) \(R_2\) \(\ldots\) \(R_M\)

  • The first line contains \(N\), the number of days in the inspection period, and \(M\), the number of books, separated by a space.
  • The second line contains \(L_1, L_2, \ldots, L_N\), the maximum number of books that can be inspected on each day, separated by spaces.
  • The third line contains \(R_1, R_2, \ldots, R_M\), the required number of inspection days for each book, separated by spaces.

【输出】

If an inspection plan that satisfies the inspection requirements for all books exists, print Yes; otherwise, print No on a single line.

【输入样例】

3 4
2 3 2
1 2 1 2

【输出样例】

Yes

【解题思路】

image

【代码详解】

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200005;int n, m;
int l[N], r[N];  // l: 学生数组, r: 老师数组signed main()
{cin >> n >> m;for (int i = 1; i <= n; i++){cin >> l[i];}for (int i = 1; i <= m; i++){cin >> r[i];}sort(l + 1, l + n + 1);  // 对学生能力排序sort(r + 1, r + m + 1, greater<int>());  // 对老师要求降序排序int suml = 0, sumr = 0;  // suml: 学生总能力, sumr: 老师总要求for (int i = 1; i <= m; i++)  // 遍历老师{sumr += r[i];  // 累加老师要求// 查找第一个能力 >= i 的学生位置int pos = lower_bound(l + 1, l + n + 1, i) - l;// 能力 >= i 的学生数量suml += (n - (pos - 1));// 如果当前学生的总能力小于老师总要求if (suml < sumr){cout << "No" << endl;return 0;}}cout << "Yes" << endl;return 0;
}

【运行结果】

3 4
2 3 2
1 2 1 2
Yes
http://www.jsqmd.com/news/527506/

相关文章:

  • 2026年水处理设备厂家推荐:纯水处理、反渗透/超纯水/软化水及各类生活/脱硫/砂浆废水处理设备优质之选! - 品牌推荐用户报道者
  • 基于 PLC1200 的自动化流水线设计探索
  • COMSOL岩石酸化模型:碳酸钙与氧化钙的随机溶解与布林克曼流动
  • NocoBase 合作伙伴计划正式发布
  • QGC地图界面自定义数据面板开发实战
  • RePKG突破Wallpaper Engine资源壁垒:解锁动态壁纸创作新可能
  • 支付宝红包套装闲置不用愁?可可收一键变现,解锁福利新玩法 - 可可收
  • 2026湖南古法炭烤手撕鸭实力厂商五强甄选与深度解析报告 - 2026年企业推荐榜
  • Verilog ISP仿真框架搭建实战:从RAW到YUV的全流程解析(附完整代码)
  • AMT102磁性编码器驱动设计与实时角度反馈实现
  • Ostrakon-VL-8B基础教程:app.py源码解析与Gradio接口自定义扩展方法
  • Selenium报错‘This version of ChromeDriver only supports Chrome version XX’?5分钟教你彻底排查与修复
  • 巨人网络发布“全时智能”客服退款投诉方案快速提升效率畅通 - 王老吉弄
  • Qwen2.5-0.5B Instruct法律文书生成:合同条款智能起草
  • Qt 开发机器人客户端程序
  • 小型项目选择2核2G云服务器够用吗?
  • 改进型可调整步长PO MPPT在光储系统中的应用:二区MPPT复现与直流负载供电单级离网光伏系统
  • TSL2561光强传感器驱动开发与嵌入式工程实践
  • Roo Code深度调教指南:如何用自定义模式+提示词打造你的前端/后端/测试专属AI助手
  • 2026年工业级白油厂家推荐:潍坊晨星化工科技,化妆级白油/食品级白油/硅酮胶专用白油厂家精选 - 品牌推荐官
  • 三相并网逆变器:电网电压690V高规格,1.5MW大容量直流源稳定供电系统
  • StarUML实战:手把手教你绘制电商系统数据流图(含常见错误排查)
  • 办公家具工厂直供选购指南:避开3大陷阱,选对省心方案 - 速递信息
  • 亲测好用! 降AIGC软件 千笔·专业降AIGC智能体 VS speedai 专为毕业论文全流程设计
  • Wemos Matrix Adafruit GFX:HT16K33点阵的GFX图形接口实现
  • 重构OpenCore配置:OpCore-Simplify全流程自动化指南
  • SVG无功补偿技术实现:定电压控制,电网电压调控灵活且迅速启动无功补偿装置优化电网响应性能
  • 多线程环境下malloc死锁的5种常见场景及避坑指南(含__lll_lock_wait_private分析)
  • 2025国内Docker镜像加速全攻略:精选源与配置实战
  • 防反接电路:背靠背Pmos组成理想二极管