当前位置:网站首页>B. Inflation-Educational Codeforces Round 103 (Rated for Div. 2)
B. Inflation-Educational Codeforces Round 103 (Rated for Div. 2)
2022-07-30 02:30:00 【秦小咩】
B. Inflation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You have a statistic of price changes for one product represented as an array of nn positive integers p0,p1,…,pn−1p0,p1,…,pn−1, where p0p0 is the initial price of the product and pipi is how the price was increased during the ii-th month.
Using these price changes you are asked to calculate the inflation coefficients for each month as the ratio of current price increase pipi to the price at the start of this month (p0+p1+⋯+pi−1)(p0+p1+⋯+pi−1).
Your boss said you clearly that the inflation coefficients must not exceed kk %, so you decided to increase some values pipi in such a way, that all pipi remain integers and the inflation coefficients for each month don't exceed kk %.
You know, that the bigger changes — the more obvious cheating. That's why you need to minimize the total sum of changes.
What's the minimum total sum of changes you need to make all inflation coefficients not more than kk %?
Input
The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The first line of each test case contains two integers nn and kk (2≤n≤1002≤n≤100; 1≤k≤1001≤k≤100) — the length of array pp and coefficient kk.
The second line of each test case contains nn integers p0,p1,…,pn−1p0,p1,…,pn−1 (1≤pi≤1091≤pi≤109) — the array pp.
Output
For each test case, print the minimum total sum of changes you need to make all inflation coefficients not more than kk %.
Example
input
Copy
2 4 1 20100 1 202 202 3 100 1 1 1
output
Copy
99 0
Note
In the first test case, you can, for example, increase p0p0 by 5050 and p1p1 by 4949 and get array [20150,50,202,202][20150,50,202,202]. Then you get the next inflation coefficients:
- 5020150≤11005020150≤1100;
- 20220150+50≤110020220150+50≤1100;
- 20220200+202≤110020220200+202≤1100;
In the second test case, you don't need to modify array pp, since the inflation coefficients are already good:
- 11≤10010011≤100100;
- 11+1≤10010011+1≤100100;
=========================================================================
常规做法肯定是线性推一遍,大于k了就增加分母,这种方法没有什么不对的,但是本题必须加正整数,而正因为这样,模数不为零的存在让我们频繁多加1,最终导致了答案总是不那么精确。
为了减少加1的次数,我们统一将加数加在p1上,枚举前缀和计算最大加数即可,这里顶多会加1,。
# include<iostream>
using namespace std;
typedef long long int ll;
ll p[1000];
ll sum[1000];
int main ()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
ll k;
cin>>k;
for(int i=1;i<=n;i++)
{
cin>>p[i];
sum[i]=sum[i-1]+p[i];
}
ll ans=0;
for(int i=2;i<=n;i++)
{
if(k*sum[i-1]<100*p[i])
{
ll t=100*p[i]-k*sum[i-1];
ll d=t/k;
if(t%k)
d++;
ans=max(ans,d);
}
}
cout<<ans<<endl;
}
return 0;
}边栏推荐
- What to test for app testing
- 信息系统项目管理师核心考点(五十四)配置项分类、状态与版本
- 实现批量导出功能
- org.apache.ibatis.binding.BindingException Invalidbound statement (not found)的解决方案和造成原因分析(超详细)
- 基于低能耗自适应聚类层次结构(LEACH)(Matlab代码实现)
- FL Studio官方20.9中文版无需汉化补丁,正确安装并设置切换
- Detailed explanation of carousel picture 2 - carousel pictures through left positioning
- go jwt use
- English语法_不定代词 -some & any
- Drawing Problem Log
猜你喜欢

RAII Technology Learning

解决:npm ERR code ELIFECYCLE npm ERR errno 1(安装脚手架过程中,在npm run dev 时发生错误)

一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?

matlab用dde23求解带有固定时滞的时滞微分方程

Hacker News Broadcast | A fake offer steals $625 million

Kotlin接口

The display and hiding of widgets for flutter learning

A plastic bottle of ocean "fantasy drifting"

零代码工具推荐---HiFlow

【服务器存储数据恢复】华为OceanStor某型号存储raid5数据恢复案例
随机推荐
【2023海康威视提前批笔试题】~ 题目及参考答案
基于蒙特卡诺的风场景模型出力(Matlab代码实现)
Push the image to the Alibaba Cloud private warehouse
菜刀、冰蝎、蚁剑、哥斯拉的流量特征
OSPF shamlink 解决后门链路问题
go jwt使用
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
JS Navigator appName appVersion userAgent platform
基于低能耗自适应聚类层次结构(LEACH)(Matlab代码实现)
anaconda打开闪退解决
go jwt use
ButtonStyle, MaterialStateProperty learned by flutter
A plastic bottle of ocean "fantasy drifting"
Oracle数据库表空间整理回收与释放操作
STM32L4R9ZIY6PTR STM32L4高性能嵌入式—MCU
nrm ls 为什么前面不带 *了
LeetCode Question of the Day (874. Walking Robot Simulation)
成功解决pydotplus.graphviz.InvocationException: GraphViz‘s executables not found
[深入研究4G/5G/6G专题-45]: 5G Link Adaption链路自适应-1-总体架构
Not enough information to list load addresses in the image map.(STM32编译报错)