当前位置:网站首页>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;
}边栏推荐
- centOS安装MySQL详解
- The box office broke 790 million US dollars. Have you watched this recent dinosaur movie?
- Postgresql daily operation and maintenance skills, suitable for beginners
- el-table sum total
- STM32L4R9ZIY6PTR STM32L4 high-performance embedded-MCU
- 共享内存-内存映射-共享文件对象
- JS Bom window innerWidth clientWidth onresize 窗口滚动偏移量 返回顶部
- 【服务器存储数据恢复】华为OceanStor某型号存储raid5数据恢复案例
- EL 表达式
- RAII技术学习
猜你喜欢
随机推荐
About offline use of SAP Fiori apps
[Notes] Stuttering word segmentation to draw word cloud map
CVPR 2022 Best Paper -- Learning to Solve Hard Minimal Problems
fluttter学习之ButtonStyle 、MaterialStateProperty
MPLS VPN跨域-optionC2
Docker installs MySQL with one click
Oracle数据库表空间整理回收与释放操作
Linux Jenkins查找缓存文件及删除 (2022-07测试可用)
复星医药募资44.84亿:高毅资产认购20亿 成第三大股东
c语言进阶篇:指针(四)
固体火箭发动机三维装药逆向内弹道计算
houdini 使用HDA Processor 实现处理HDA输入输出
Fudan-Washington University EMBA Kechuang's Ao E丨The Magical Materials and We Are Shaped
Leetcode.24 两两交换链表中的节点(递归)
A transaction is in Mysql?What's the use?
计算机复试面试题总结
解决:npm ERR code ELIFECYCLE npm ERR errno 1(安装脚手架过程中,在npm run dev 时发生错误)
复旦-华盛顿大学EMBA科创的奥E丨《神奇的材料》与被塑造的我们
Is it difficult for AI to land?Cloud native helps enterprises quickly apply machine learning MLOps
JS Navigator appName appVersion userAgent platform









