Problem:
Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

In one attack, Serval can decrease the monster's health by A.
There is no other way to decrease the monster's health.

Serval wins when the monster's health becomes 0 or below.

Find the number of attacks Serval needs to make before winning.

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

Print the number of attacks Serval needs to make before winning.

Sample Input 1

10 4

Sample Output 1

3

After one attack, the monster's health will be 6.

After two attacks, the monster's health will be 2.

After three attacks, the monster's health will be -2.

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000

Solution in C (GCC 5.4.1) (judge verdict: Runtime Error)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define MAX_N 1000
#define MAX_B 10000
int dp[MAX_N + 1][MAX_B + 1];
int main() {
    int h, n;
    scanf("%d %d", &h, &n);
    int *a = malloc(sizeof(int) * n); // attack
    int *b = malloc(sizeof(int) * n); // cost
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a[i], &b[i]);
    }

for (int i = 0; i <= h; i++) {
    for (int j = 0; j <= h; j++) {
        dp[i][j] = 1000000;
    }
}
dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= h; j++) {
            if (j <= a[i]) {
                dp[i+1][j] = MIN(dp[i][j], dp[i+1][0] + b[i]);
                //printf("1) %d, %d, %d\n", i, j, dp[i+1][j]);
            } else {
                dp[i+1][j] = MIN(dp[i][j], dp[i+1][j-a[i]] + b[i]);
                //printf("2) %d, %d, %d\n", i, j, dp[i+1][j]);
            }
        }
    }

    /*
        for (int i = 0; i < n + 1; i++) {
        for (int j = 0; j < h + 1; j++) {
            printf("%d ", dp[i][j]);
        }
        printf("\n");

    }
    */
    printf("%d", dp[n][h]);
    return 0;
}