codeforces1476B. Inflation

https://codeforces.com/contest/1476/problem/B

啊艹被这道傻逼题卡了一万年,早点写cd就好了

这题只要发现肯定是放在p[1]增加更优,那么就扫一遍就行了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxl=3e5+10;

int n,m,k,tot,cnt;ll tmp,ans;
ll a[maxl],sum[maxl],b[maxl],p[maxl];
char s[maxl];
bool vis[maxl];

inline void prework()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i];		
}

inline void mainwork()
{
	ans=0;
	for(int i=2;i<=n;i++)
	if(a[i]*100>k*(ans+sum[i-1]))
	{
		ll d=a[i]*100-k*sum[i-1];
		ans=d/k+(d%k!=0);
	}
}

inline void print()
{
	printf("%lld\n",ans);
}

int main()
{
	int t=1;
	scanf("%d",&t);
	while(t--)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/liufengwei1/article/details/113409292