1. 程式人生 > >Codeforces Round #518 (Div. 2) A. Birthday 思維

Codeforces Round #518 (Div. 2) A. Birthday 思維

A. Birthday

Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms:

Everyone must gift as many coins as others.
All coins given to Ivan must be different.
Not less than L coins from gifts altogether, must be new in Ivan’s collection.
But his friends don’t know which coins have Ivan already got in his collection. They don’t want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan’s collection. Help them to find this minimum number of coins or define it’s not possible to meet all the terms.

Input
The only line of input contains 4 integers N, M, K, L (1≤K≤N≤1018; 1≤M,L≤1018) — quantity of different coins, number of Ivan’s friends, size of Ivan’s collection and quantity of coins, that must be new in Ivan’s collection.

Output
Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print “-1” (without quotes).

Examples
inputCopy
20 15 2 3
outputCopy
1
inputCopy
10 11 2 4
outputCopy
-1
Note
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.

In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can’t present him different coins.

這題的意思是有n個人來為你慶祝生日,他們給你紀念幣為禮物,其中,紀念幣總共有m種,而你已經有了k種,要求是朋友們送給你的紀念幣至少有l種是你沒有的。另外,每個朋友給的硬幣都是不一樣的,但是個數是一樣的,求每個朋友送的最少個數。一開始我的思路是列舉每個朋友的送的個數,看是否滿足n*ans-l>k,但是在codeforces裡做題,列舉這種做法一向是比較愚蠢的(我就很愚蠢)。所以,我們知道,需要的硬幣數僅僅是至少k+L種,所以若(k+L) %m==0 ,則只需要(k+l)/m枚,若不為零,則再加一枚,若需要的已經大於所有n種,自然無法再分配

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{

	unsigned long long n,m,k,l,ans=0;
	cin>>n>>m>>k>>l;
	int flag=1;
	if(k+l>n||n<m)
		flag=1;
	else
		{	
			
			ans=(l+k)/m;
			flag=0;
	
			if((l+k)%m==0)
				ans=(l+k)/m;
			else
				ans++;
			if(ans*m>n)
				flag=1;			
		
		}
	if(flag)
		printf("-1\n");
	else
		cout<<ans<<endl;
	return 0;
}