Particularly, I've got just one possible solution of the problem you've claimed:
I don't actually know what SelectAgent and SelectObject functions are supposed to do, that's why I replaced them with two "trap" functions generating random values, which you'll need to substitute with the ones the perform the right things for you.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define AGENTS_N 5 // The number of agents
#define OBJECTS_N 10 // The number of objects
int SelectAgent() { return rand() % AGENTS_N; }
int SelectObject() { return rand() % OBJECTS_N; }
int GetSum() { return rand() % (AGENTS_N * OBJECTS_N) + 1; }
int main()
{
int** a = new int*[AGENTS_N];
int* sizes = new int[AGENTS_N];
for (int t = 0; t < AGENTS_N; t++)
sizes[t] = OBJECTS_N;
for (int i = 0; i < AGENTS_N; i++)
{
a[i] = new int[OBJECTS_N];
memset((void*)a[i], 0x00, sizeof(int) * OBJECTS_N);
}
int SUM = GetSum();
while (SUM > 0)
{
int i = SelectAgent(); int k = SelectObject();
int rand_val = rand() % 0xFF + 1;
printf("agent = %d object = %d value = %d\n", i, k, rand_val);
if (a[i][k] <= 0)
{
a[i][k] = rand_val;
for (int x = 0; x < sizes[i]; x++)
printf("%d ", a[i][x]);
printf("\n");
}
else
{
int new_size = sizes[i] + 1;
int* temp = new int[new_size];
memcpy((void*)temp, (const void*)a[i], sizeof(int) * sizes[i]);
for (int t = sizes[i]; t >= k; t--)
a[i][t + 1] = a[i][t];
a[i][k] = rand_val; sizes[i] = new_size;
for (int x = 0; x < sizes[i]; x++)
printf("%d ", a[i][x]);
printf("\n");
}
SUM = SUM - 1;
}
return 0;
}</conio.h></stdlib.h></stdio.h>
P.S. If you've got any questions, just post your comments under my solution for your question. That's all folks.