URAL 1783 Nuclear Arms Race

Western and Eastern Cuckooland are close to the outbreak of war. Superpowers are competing for supremacy in nuclear warfare to achieve dominance in the military sphere. Unfortunately, production and stockpiling of nuclear warheads are very expensive and can easily undermine the budgets of both countries.
Military analysts and economists of Western Cuckooland have provided a report according to which the country will be safe and the budget will be stable, if by the end of the i-th month there would be exactly ai warheads stockpiled in warehouses. The president ordered to adhere to these figures, so the plants in Western Cuckooland produce or dispose the necessary amount of warheads each month.
But the intelligence of Eastern Cuckooland is great! At the begining of the i-th month the spies from Eastern Cuckooland get access to the plans of Western Cuckooland for the next m months (that is, the numbers aiai + 1, …, ai + m − 1) and send them home. When dictator of Eastern Cuckooland receives this information, he immediately gives the order to change the current number of warheads in warehouses in Eastern Cuckooland by a number xi. He chooses xi, in such a way that if Eastern Cuckooland would change the number of warheads by xi during m months, it would have not less warheads than Western Cuckooland by the end of every month. The dictator also cares about the country's budget, therefore, he chooses the minimal possible xi.
Determine what orders the dictator of Eastern Cuckooland will give during the first n months. You can assume that at the beginning of the first month, neither Western nor Eastern Cuckooland posess nuclear arsenal.

Input

The first line contains space-separated integers n and m (1 ≤ n ≤ 10000; 1 ≤ m ≤ 50). The second line contains space-separated integers a1, …, an + m − 1 (0 ≤ ai ≤ 105), which are the plans of the Western Cuckooland.

Output

Output a list of space-separated integers x1, …, xn. Number xi corresponds to the order the dictator of Eastern Cuckooland will give at the begining of the i-th month.

Sample

input output
4 3
0 0 4 2 1 0
2 1 1 -1

HintProblem illustration

题目读了我几天,真心被坑啊。
题意:左边的数组代表敌人n+m-1月内的核弹头的计划,你已经知道了从i月开始,未来m月的敌人的核弹头计划,根据这个你要制定一个+,-核弹头的计划,使得你的核弹头的数目不少于敌人的。关键是要这个值是要能选取的里面,最小的那个。此题不是special judge,答案是唯一。


解题:从当前月到第i个月平均每天做(a[i]-s)/i个核弹头才能使得到第i个月有a[i]个,(s是目前已经拥有的核弹头) 而且是最小的(因为是平均的),如果不能整除,说明肯定有一个大的,所以做除法时可以向上取整。这样就解释了为什么样例输出的2会出现在第一个月,而不是第二个,第三个月。(其实我觉得 1 1 2 -1,    1 2 1 -1 的答案也没什么错。)
#include<cstdio>
#include<cmath>
int main()
{
	int a[20010];
	int n,m,i,tmp;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=1;i<n+m;i++)
			scanf("%d",&a[i]);
		int k;
		int s=0;
		for(k=0;k<n;k++)
		{
		    int max=-0x3f3f3f3f;
		    for(i=1;i<=m;i++)
			{
			   tmp=(int)ceil(((a[i+k]-s)*1.0/i));
			   if(tmp>max)
				 max=tmp;
			}
			s+=max;
			if(!k) printf("%d",max);
			else printf(" %d",max);			
		}putchar(10);
	}
	return 0;
}





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TommyTT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值