资讯动态

题解:AtCoder AT_awc0004_b Battery Level

发布时间:2026/9/30 16:35:04 来源:尧图企业网站定制
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderB - Battery Level【题目描述】Takahashi is developing a system to monitor the charging status ofN NNsmartphones.高桥正在开发一个监控N NN部智能手机充电状态的系统。At time0 00, the battery level of each smartphonei ii(1 ≤ i ≤ N 1 \leq i \leq N1≤i≤N) isA i A_iAi​mAh. Each smartphonei iiconsumes battery at a constant rate ofB i B_iBi​mAh/s from time0 00onwards. However, the battery level does not go below0 00mAh.在时刻0 00每部智能手机i ii1 ≤ i ≤ N 1 ≤ i ≤ N1≤i≤N的电量为A i A_iAi​毫安时。每部智能手机i ii从时刻0 00起以恒定速率B i B_iBi​毫安时/秒消耗电量。但是电量不会低于0 00毫安时。That is, the battery level of smartphonei iiat timet tt(t ≥ 0 t \geq 0t≥0) ismax ⁡ ( A i − B i × t , 0 ) \max(A_i - B_i \times t,\ 0)max(Ai​−Bi​×t,0)mAh.也就是说智能手机i ii在时刻t ttt ≥ 0 t ≥ 0t≥0的电量为m a x ( A i − B i × t , 0 ) max(A_i - B_i × t, 0)max(Ai​−Bi​×t,0)毫安时。Find the total battery level of allN NNsmartphones at timeT TT.求在时刻T TT所有N NN部智能手机的总电量。【输入】N NNT TTA 1 A_1A1​B 1 B_1B1​A 2 A_2A2​B 2 B_2B2​⋮ \vdots⋮A N A_NAN​B N B_NBN​The first line contains an integerN NNrepresenting the number of smartphones and an integerT TTrepresenting the time at which to calculate the total battery level, separated by a space.Lines2 22throughN 1 N1N1give the information for each smartphone.Line1 i 1 i1icontains an integerA i A_iAi​representing the initial battery level of smartphonei iiand an integerB i B_iBi​representing the battery consumption per second, separated by a space.【输出】Output the total battery level of all smartphones at timeT TTas an integer on a single line.【输入样例】3 5 100 10 30 8 50 20【输出样例】50【解题思路】【算法标签】#模拟#【代码详解】#includebits/stdc.husingnamespacestd;#defineintlonglongconstintN200005;intn,t;// n: 数据对数t: 时间参数intans;// 结果signedmain(){cinnt;// 读入n和tfor(inti1;in;i){inta,b;// a: 初始值b: 衰减系数cinab;// 读入a和b// 计算max(0, a - b*t)并累加到ansansmax(0ll,a-b*t);}coutansendl;// 输出结果return0;}【运行结果】3 5 100 10 30 8 50 20 50

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑