题解:AtCoder AT_awc0082_a Store Sales Calculation

发布时间:2026/6/3 13:04:53

题解:AtCoder AT_awc0082_a Store Sales Calculation 本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】AtCoderA - Store Sales Calculation【题目描述】Takahashi runs a store. This store sellsN NNtypes of products, each distinguished by a number from1 11toN NN. The regular price of producti iiisA i A_iAi​yen per item.This store has a membership system, where member customers receive a discount ofK KKyen per item. Specifically, when a non-member customer purchases producti ii, the price per item is the regular price ofA i A_iAi​yen. When a member customer purchases producti ii, the price per item ismax ⁡ ( A i − K , 0 ) \max(A_i - K, 0)max(Ai​−K,0)yen, which is the regular price minusK KKyen (the discount does not exceed the regular price, and the price does not go below0 00yen).Now,M MMpurchase records are given. Thej jj-th record contains a valueS j S_jSj​indicating whether the customer is a member (1 11for member,0 00for non-member), the product numberP j P_jPj​purchased, and the quantityD j D_jDj​purchased.The purchase amount for each record is the price per item multiplied by the quantityD j D_jDj​. Find the total purchase amount across all purchase records.高桥经营一家商店。这家商店销售N NN种产品每种产品用1 11到N NN的数字区分。产品i ii的常规价格是每件A i A_iAi​日元。这家商店有一个会员系统会员顾客每件商品可享受K KK日元的折扣。具体来说当非会员顾客购买产品i ii时每件价格是常规价格A i A_iAi​日元。当会员顾客购买产品i ii时每件价格是max ⁡ ( A i − K , 0 ) \max(A_i - K, 0)max(Ai​−K,0)日元即常规价格减去K KK日元折扣不超过常规价格价格不低于0 00日元。现在给出了M MM条购买记录。第j jj条记录包含一个值S j S_jSj​表示顾客是否为会员1 11为会员0 00为非会员购买的产品编号P j P_jPj​以及购买的数量D j D_jDj​。每条记录的购买金额是每件价格乘以数量D j D_jDj​。求所有购买记录的总购买金额。【输入】N NNM MMK KKA 1 A_1A1​A 2 A_2A2​⋯ \cdots⋯A N A_NAN​S 1 S_1S1​P 1 P_1P1​D 1 D_1D1​S 2 S_2S2​P 2 P_2P2​D 2 D_2D2​⋮ \vdots⋮S M S_MSM​P M P_MPM​D M D_MDM​The first line contains the number of product typesN NN, the number of purchase recordsM MM, and the member discount amountK KK, separated by spaces.The second line containsN NNintegersA 1 , A 2 , … , A N A_1, A_2, \ldots, A_NA1​,A2​,…,AN​, separated by spaces.Thej jj-th line( 1 ≤ j ≤ M ) (1 \leq j \leq M)(1≤j≤M)of the followingM MMlines contains the membership statusS j S_jSj​, the product numberP j P_jPj​, and the quantity purchasedD j D_jDj​for thej jj-th purchase record, separated by spaces.【输出】Output the total purchase amount across all purchase records in a single line.【输入样例】3 4 20 100 50 10 0 1 2 1 2 3 1 3 5 0 2 1【输出样例】340【算法标签】#模拟【代码详解】#includebits/stdc.husingnamespacestd;#defineintlonglongconstintN200005;intn,m,k,ans;// n: 数组长度m: 操作数量k: 阈值ans: 总结果inta[N];// 存储数组signedmain(){cinnmk;// 输入数组长度、操作数量和阈值for(inti1;in;i)// 输入数组元素cina[i];for(inti1;im;i)// 处理每个操作{ints,p,d;// s: 操作类型p: 位置d: 倍数cinspd;// 输入操作参数if(s1)// 如果操作类型为1ansmax(a[p]-k,0LL)*d;// 计算贡献并累加else// 如果操作类型为2ansa[p]*d;// 计算贡献并累加}coutansendl;// 输出总结果return0;}【运行结果】3 4 20 100 50 10 0 1 2 1 2 3 1 3 5 0 2 1 340

相关新闻