poj 3427 Ecology tax

Ecology tax
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4503 Accepted: 2363

Description

In a big and rich on natural resources country, the government started a campaign to control deforestation. In fact the government is not too interested in how many trees get fallen, but rather how effectively the wood is utilized. So a law was passed which requires every logging company to pay amount of money in proportion to amount of wood that it wastes during operation.

A felling quota on some territory was allotted to a company in this country. Company lorries may only transport logs of exactly L meters long. So when a tree gets sawed into logs, the remainder is wasted.

Trees in this country grow exactly 1 meter per year, so the company may decrease the amount of tax to be paid by simply waiting for some years. Your task is to determine the number of years needed to achieve smallest possible tax. If there is more than one answer, find minimal (earliest) one.

Input

Input file contains number of trees N, length of log L, followed by integers i1 i2 ... iN — heights of each tree.

Constraints

1 ≤ N ≤ 30000, 1 ≤ Lik ≤ 30000

Output

Output file must contain single integer — number of years to wait.

Sample Input

Sample Input 1
3 1 
10 15 11
Sample Input 2
3 2
5 3 6

Sample Output

Sample Output 1
0
Sample Output 2
1

Hint

Bold texts appearing in the sample sections are informative and do not form part of the actual data.


题意:实质为给出n个数,他们的值为tree,以及一个数l。求出max(l - tree[1~n] % l)

注意:题目中的Sample Input 1  不参与输入,其输出中的那个也不参与;

#include <iostream>
using namespace std;
int main(){
	int n,l,tree,t;
	char s[100],ss[100];
	while (cin>>n>>l){
		int max=0;
		for (int i=0;i<n;i++){
			cin>>tree;
			if (tree%l==0)
				continue;
			int k=l-tree%l;
			if (max<k)
				max=k;
		}
		cout<<max<<endl;
	}
	return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值