You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.
You are minimalist. Therefore, on the one hand, you are against dividing some box into more than k sections. On the other hand, you are against putting more than v nuts into some section of the box. What is the minimum number of boxes you have to use if you want to put all the nuts in boxes, and you have b divisors?
Please note that you need to minimize the number of used boxes, not sections. You do not have to minimize the number of used divisors.
The first line contains four space-separated integers k, a, b, v (2 ≤ k ≤ 1000; 1 ≤ a, b, v ≤ 1000) — the maximum number of sections in the box, the number of nuts, the number of divisors and the capacity of each section of the box.
Print a single integer — the answer to the problem.
3 10 3 3
2
3 10 1 3
3
100 100 1 1000
1
In the first sample you can act like this:
- Put two divisors to the first box. Now the first box has three sections and we can put three nuts into each section. Overall, the first box will have nine nuts.
- Do not put any divisors into the second box. Thus, the second box has one section for the last nut.
In the end we've put all the ten nuts into boxes.
The second sample is different as we have exactly one divisor and we put it to the first box. The next two boxes will have one section each.
#include <stdio.h>
#include <string.h>
#include <math.h>
int change (int n, int x)
{
if (n % x == 0) return n / x;
else return n / x + 1;
}
int main()
{
int k, a, b, v, ans;
while (scanf("%d%d%d%d", &k, &a, &b, &v) != EOF)
{
ans = 0;
int num = b / (k-1);
int num2 = b % (k-1);
if (num*v*k >= a) {ans = change(a,v*k);}
else if (num*v*k + (num2 + 1)*v >= a) ans = num + 1;
else
{
int left = a - (num*v*k + (num2 + 1)*v);
ans = change(left, v) + num + 1;
}
//printf("%d %d %d %d %d\n", change(left, v), num2, left, v, num*v*k + (num2 + 1)*v);
printf("%d\n", ans);
}
return 0;
}
The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height ai meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n),ai + 1 - ai = k, where k is the number the Queen chose.
Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?
The first line contains two space-separated integers: n, k (1 ≤ n, k ≤ 1000). The second line contains n space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 1000) — the heights of the trees in the row.
In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions.
If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x".
If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.
4 1 1 2 1 5
2 + 3 2 - 4 1
4 1 1 2 3 4
0