Codeforces Round #571 (Div. 2) D Vus the Cossack and Numbers (思维)

D. Vus the Cossack and Numbers

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vus the Cossack has n real numbers ai. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is n such that the sum of all numbers is 0 and each bi is either ⌊ai⌋ or ⌈ai⌉. In other words, bi equals ai

rounded up or down. It is not necessary to round to the nearest integer.For example, if a=[4.58413,1.22491,−2.10517,−3.70387], then b can be equal, for example, to [4,2,−2,−4]

.

Note that if ai

is an integer, then there is no difference between ⌊ai⌋ and ⌈ai⌉, bi will always be equal to ai

Help Vus the Cossack find such sequence!

Input

The first line contains one integer n (1≤n≤105) — the number of numbers.

Each of the next n lines contains one real number ai (|ai|<105). It is guaranteed that each ai has exactly 5 digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to 0

Output

In each of the next n

lines, print one integer bi. For each i, |ai−bi|<1 must be met.

If there are multiple answers, print any.

Examples

Input

4
4.58413
1.22491
-2.10517
-3.70387

Output

4
2
-2
-4

Input

5
-6.32509
3.30066
-0.93878
2.00000
1.96321

Output

-6
3
-1
2
2

题目保证给出的数和为0,先对所有数向下取整,这时,所有数(除了整数)都会减小,把和求出来,肯定小于0或等于0。当等于0时,直接输出即可。若小于0,那么我们就要改变数的值,将它+1(除了本就是整数的数,因为不能改变它的值,题目说得,没看到。。)。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+10;
double a[N];
int b[N];
int main(void)
{
	int n;
	ll diff=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&a[i]);
		b[i]=floor(a[i]);
		diff+=b[i];
	}
	for(int i=1;i<=n&&diff<0;i++)
	{
		if(a[i]-b[i]<1e-6) continue;
		diff++;
		b[i]++;
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",b[i]);
	
	return 0;
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值