codeforces #509(Div.3) A B C 题解 ʕ •ᴥ•ʔ

把烦恼 懂了 吞了 认了 算了 不对别人讲 !

A. Heist

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There was an electronic store heist last night.

All keyboards which were in the store yesterday were numbered in ascending order from some integer number xx. For example, if x=4x=4 and there were 33 keyboards in the store, then the devices had indices 44, 55 and 66, and if x=10x=10 and there were 77 of them then the keyboards had indices 1010, 1111, 1212, 1313, 1414, 1515 and 1616.

After the heist, only nn keyboards remain, and they have indices a1,a2,…,ana1,a2,…,an. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither xx nor the number of keyboards in the store before the heist.

Input

The first line contains single integer nn (1≤n≤1000)(1≤n≤1000) — the number of keyboards in the store that remained after the heist.

The second line contains nn distinct integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109) — the indices of the remaining keyboards. The integers aiai are given in arbitrary order and are pairwise distinct.

Output

Print the minimum possible number of keyboards that have been stolen if the staff remember neither xx nor the number of keyboards in the store before the heist.

Examples

input

Copy

4
10 13 12 8

output

Copy

2

input

Copy

5
7 5 6 4 8

output

Copy

0

Note

In the first example, if x=8x=8 then minimum number of stolen keyboards is equal to 22. The keyboards with indices 99 and 1111were stolen during the heist.

In the second example, if x=4x=4 then nothing was stolen during the heist.

传送门

题意:输入一个n 表示商店悲哀抢劫后剩下的键盘数量   然后输入 n 个被偷了的编号 员工不知道一开始的编号 问你最少有多少个物品被偷  水题 自看代码

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a[1010];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	cout<<a[n-1]-a[0]-n+1<<endl;
	return 0;
}

 

B. Buying a TV Set

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a

and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: wh=xy

.

There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w

and h there is a TV set with screen width w and height h

in the shop.

Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w

and h, beforehand, such that (w≤a), (h≤b) and (wh=xy)

.

In other words, Monocarp wants to determine the number of TV sets having aspect ratio xy

, screen width not exceeding a, and screen height not exceeding b

. Two TV sets are considered different if they have different screen width or different screen height.

Input

The first line contains four integers a

, b, x, y (1≤a,b,x,y≤1018

) — the constraints on the screen width and height, and on the aspect ratio.

Output

Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.

Examples

Input

Copy

17 15 5 3

Output

Copy

3

Input

Copy

14 16 7 22

Output

Copy

0

Input

Copy

4 2 6 4

Output

Copy

1

Input

Copy

1000000000000000000 1000000000000000000 999999866000004473 999999822000007597

Output

Copy

1000000063

Note

In the first example, there are 3 possible variants: (5,3), (10,6), (15,9)

In the second example, there is no TV set meeting the constraints.

In the third example, there is only one variant: (3,2)

传送门

题意:给你四个数 求gcd(c,d)==1时  从一到 a // 1到 b 有多少可以经过约分 变成 c d

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll t=__gcd(c,d);
	c=c/t,d=d/t;
	a=a/c,b=b/d;
	cout<<min(a,b)<<endl;
	return 0;
}

 

C. Coffee Break

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently Monocarp got a job. His working day lasts exactly m

minutes. During work, Monocarp wants to drink coffee at certain moments: there are n minutes a1,a2,…,an

, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute).

However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute ai

, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least d minutes pass between any two coffee breaks. Monocarp also wants to take these n coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than d

minutes pass between the end of any working day and the start of the following working day.

For each of the n

given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.

Input

The first line contains three integers n

, m, d (1≤n≤2⋅105,n≤m≤109,1≤d≤m)

 — the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks.

The second line contains n

distinct integers a1,a2,…,an (1≤ai≤m), where ai

is some minute when Monocarp wants to have a coffee break.

Output

In the first line, write the minimum number of days required to make a coffee break in each of the n

given minutes.

In the second line, print n

space separated integers. The i-th of integers should be the index of the day during which Monocarp should have a coffee break at minute ai. Days are numbered from 1

. If there are multiple optimal solutions, you may print any of them.

Examples

Input

Copy

4 5 3
3 5 1 2

Output

Copy

3
3 1 1 2 

Input

Copy

10 10 1
10 5 7 4 6 3 2 1 9 8

Output

Copy

2
2 1 1 2 2 1 2 1 1 2 

Note

In the first example, Monocarp can take two coffee breaks during the first day (during minutes 1

and 5, 3 minutes will pass between these breaks). One break during the second day (at minute 2), and one break during the third day (at minute 3

).

In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.

题意:给你n个 这个人可以休息的时间点 每天工作是m小时 两个点之间的距离需要大于 d  问你最少可以休息几天 其实就是将这些数进行离散话 直接看代码把

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
pair<int,int>p[200010];
int a[200010];
int ans[200010];
int main()
{
	int n,b,d;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>p[i].first;
		p[i].second=i;
	}
	sort(p,p+n);
	int day=1;
	int c=0;
	for(int i=0;i<n;i++)
	{
		if(p[i].first-p[c].first<=d)
		{
			a[i]=day++;
		}
		else
		a[i]=a[c++];
	}
	cout<<day-1<<endl; 
	for(int i=0;i<n;i++)
	{
		ans[p[i].second]=a[i];
	}
	for(int i=0;i<n;i++)
	cout<<ans[i]<<" "; 
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值