#include <stdio.h>

int main() {
    int block[20], process[20], frag[20], blockCount, processCount;
    int allocation[20], occupied[20];
    int i, j, lowest, temp;

    printf("\n\t\t\tMemory Management Scheme - Best Fit\n");

    printf("Enter the number of blocks: ");
    scanf("%d", &blockCount);
    printf("Enter the number of processes: ");
    scanf("%d", &processCount);

    printf("\nEnter the size of the blocks:\n");
    for (i = 0; i < blockCount; i++) {
        printf("Block no.%d: ", i + 1);
        scanf("%d", &block[i]);
        occupied[i] = 0;
    }

    printf("\nEnter the size of the processes:\n");
    for (i = 0; i < processCount; i++) {
        printf("Process no.%d: ", i + 1);
        scanf("%d", &process[i]);
        allocation[i] = -1; 
    }

    for (i = 0; i < processCount; i++) {
        lowest = 10000; 
        for (j = 0; j < blockCount; j++) {
            if (!occupied[j] && block[j] >= process[i]) {
                temp = block[j] - process[i];
                if (temp < lowest) {
                    allocation[i] = j;
                    frag[i] = temp;
                    lowest = temp;
                }
            }
        }
        if (allocation[i] != -1)
            occupied[allocation[i]] = 1;
    }

   
    printf("\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment");
    for (i = 0; i < processCount; i++) {
        if (allocation[i] != -1) {
            printf("\n%d\t\t%d\t\t%dd\t\t%d\t\t %d\t\t%d", i, c[i], carr[i], b[carr[i]], a[i]);
}
printf("\n");
}