forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path306A - Candies.cpp
51 lines (36 loc) · 1.53 KB
/
306A - Candies.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Polycarpus has got n candies and m friends (n?=?m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1?=?n,?m?=?100;n?=?m) — the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1,?a2,?...,?am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
inputCopy
12 3
outputCopy
4 4 4
inputCopy
15 4
outputCopy
3 4 4 4
inputCopy
18 7
outputCopy
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int equal = n / m;
int extra = n % m;
for (int i = 1; i <= m - extra; i++) cout << equal << " ";
for (int i = m - extra + 1; i <= m; i++) cout << equal + 1 << " ";
return 0;
}