//
// Created by xfj12 on 2025/3/26.
//
#include <solution/2829.h>
#include <stdbool.h>
#include <stdlib.h>

int minimumSum(int n, int k)
{
    int *KAvoid = malloc(sizeof(int) * n);
    int idx = 1;
    KAvoid[0] = 1;

    int sum = 0;

    for (int i = 2; idx < n; i++)
    {
        bool flag = true;
        for (int j = 0; j < idx && flag; j++)
            if (KAvoid[j] + i == k)
                flag = false;
        if (flag)
            KAvoid[idx++] = i;
    }

    for (int i = 0; i < n; i++)
        sum += KAvoid[i];

    free(KAvoid);
    return sum;
}
