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

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

A - Typhoon Damage Survey

【题目来源】

AtCoder:A - Typhoon Damage Survey

【题目描述】

Takahashi is the caretaker of an orchard. There are \(N\) fruit trees planted in this orchard, numbered \(1, 2, \ldots, N\). The height of fruit tree \(i\) is \(H_i\).
高桥是一个果园的看护人。这个果园中种有 \(N\) 棵果树,编号为 \(1, 2, …, N\)。果树 \(i\) 的高度为 \(H_i\)

Last night, a large typhoon passed through this area. Due to the typhoon's strong winds, fruit trees with height \(T\) or less had not yet developed sufficient roots and all fell over. That is, fruit tree \(i\) has fallen if and only if \(H_i \leq T\).
昨晚,一场强台风经过了这个地区。由于台风的强风,高度不超过 \(T\) 的果树因根系尚未充分发育而全部倒伏。也就是说,果树 \(i\) 倒伏当且仅当 \(H_i ≤ T\)

To restore the orchard, Takahashi decided to replant all the fallen fruit trees. The cost to replant fruit tree \(i\) and restore it to its original state is \(C_i\).
为了恢复果园,高桥决定重新种植所有倒伏的果树。重新种植果树 \(i\) 并将其恢复到原始状态的成本是 \(C_i\)

Find the total cost required to restore all fallen fruit trees to their original state.
求将所有倒伏的果树恢复到原始状态所需的总成本。

【输入】

Input is given from standard input in the following format.

\(N\) \(T\)
\(H_1\) \(H_2\) \(\ldots\) \(H_N\)
\(C_1\) \(C_2\) \(\ldots\) \(C_N\)

  • The first line contains an integer \(N\) representing the number of fruit trees and an integer \(T\) representing the height threshold for trees falling, separated by a space.
  • The second line contains integers \(H_1, H_2, \ldots, H_N\) representing the height of each fruit tree, separated by spaces.
  • The third line contains integers \(C_1, C_2, \ldots, C_N\) representing the restoration cost for replanting each fruit tree, separated by spaces.

【输出】

Output in a single line the total cost required to restore all fallen fruit trees (fruit trees \(i\) satisfying \(H_i \leq T\)). If no fruit trees have fallen, output \(0\). Include a newline at the end.

【输入样例】

5 3
1 5 3 4 2
10 20 30 40 50

【输出样例】

90

【解题思路】

image

【代码详解】

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200005;int n, t, h[N], c[N], ans;  // n: 物品数量,t: 阈值// h: 高度数组,c: 价值数组,ans: 总价值signed main()
{cin >> n >> t;  // 读入物品数量和阈值for (int i = 1; i <= n; i++){cin >> h[i];  // 读入每个物品的高度}for (int i = 1; i <= n; i++){cin >> c[i];  // 读入每个物品的价值}// 统计高度不超过阈值的物品的总价值for (int i = 1; i <= n; i++){if (h[i] <= t)  // 如果高度不超过阈值{ans += c[i];  // 累加价值}}cout << ans << endl;  // 输出总价值return 0;
}

【运行结果】

5 3
1 5 3 4 2
10 20 30 40 50
90
http://www.jsqmd.com/news/442904/

相关文章:

  • 2026年资深的金融证券律师排名,哪家口碑比较靠谱 - 工业品网
  • 写作压力小了!千笔写作工具,冠绝行业的AI论文写作软件
  • 医疗设备互联中的电磁干扰屏蔽设计
  • 20天 | 终于拿到阿里云ACP大模型证书了~
  • 3月实测!帮你找到市面上口碑好的岩棉板厂家公司,保温结构一体板/保温装饰一体板/岩棉板,岩棉板厂商推荐 - 品牌推荐师
  • Bootloader安全架构设计
  • 瓷砖实力强的厂家有哪些 北京地区性价比高且口碑好的品牌推荐 - mypinpai
  • 嵌入式C语言的增强机制
  • 新电脑需要下些什么软件?
  • 【开题答辩全过程】以 平价药店销售与管理系统为例,包含答辩的问题和答案
  • 2026年高性价比A3理光3300瓷像打印机品牌大盘点 - 工业品牌热点
  • 【开题答辩全过程】以 高校宿舍管理系统为例,包含答辩的问题和答案
  • 想转行做AI大模型算法工程师需要搞定哪些知识呢?
  • bcftools 对vcf文件的名称进行批量重命名
  • 普通人入职AI行业指南:半路转行,真的比科班差吗?
  • MySQL单表真能存21亿条数据吗?会有严重的性能问题吗?
  • 2026最新有赞小程序/GEO搜索优化/GEO优化/外呼/AI优化推荐:全域数字化赋能,这家实力突出 - 十大品牌榜
  • 想转行AI产品经理,90%的人第一步就走错了
  • 国家金融监督管理总局(金管局)国考计算机类专业科目:全知识点深度解析与备考指南
  • 2026年全国彩车彩船主题定制品牌推荐,靠谱的正规供应商有哪些 - myqiye
  • 2026年市面上口碑好的粒子钢压块成型液压机生产线厂家推荐榜单,粒子钢冷压成型/金属屑压块成型/液压金属打包/自动化生产线集成,粒子钢压块成型液压机制造企业怎么选 - 品牌推广师
  • (简洁版)国家金融监督管理总局(金管局)国考计算机类专业科目终极通关宝典(全考点覆盖+真题精析+备考策略)
  • 武商一卡通回收指南:快速、可靠的兑换流程揭秘 - 团团收购物卡回收
  • PCB顺序层压法哪个好?猎板AI精准掌控翘曲度
  • 2026最新GEO搜索优化推荐!山东青岛优质服务商权威榜单发布 - 十大品牌榜
  • 做海外人力资源服务的公司有哪些?澳洲名义雇主EOR服务商推荐 - 品牌2026
  • 闲置京东 E 卡怎么变现?手把手教你安全高效的变现方法 - 团团收购物卡回收
  • 2026最新有赞小程序推荐!山东优质服务商权威榜单发布 - 十大品牌榜
  • 2026石家庄成人舞蹈培训机构优质推荐榜 - 资讯焦点
  • 电脑---关闭烦人的文件预览功能