#include #define INFTY 10000047 typedef struct { int tovar, treba, slot; } tRec; tRec H[1500]; int kdevH[1000047]; static int B,G,N; int tovary[1000047]; int next[1000047]; int seen[1000047]; void init() { int i; memset(kdevH,0,sizeof(kdevH)); for (i=1;i<=B;i++) { H[i].tovar=-1; H[i].treba=INFTY+5; H[i].slot=i; } } void bubbleup(int idx) { tRec pom; if (idx==1) return; if (H[idx/2].treba < H[idx].treba) { pom=H[idx/2]; H[idx/2]=H[idx]; H[idx]=pom; kdevH[H[idx].tovar]=idx; kdevH[H[idx/2].tovar]=idx/2; bubbleup(idx/2); } } void bubbledown(int idx) { int kam; tRec pom; kam=idx; if ((2*idx<=B) && (H[2*idx].treba > H[kam].treba)) kam=2*idx; if ((2*idx+1<=B) && (H[2*idx+1].treba > H[kam].treba)) kam=2*idx+1; if (kam!=idx) { pom=H[kam]; H[kam]=H[idx]; H[idx]=pom; kdevH[H[idx].tovar]=idx; kdevH[H[kam].tovar]=kam; bubbledown(kam); } } int main(void) { int ev,i,kejz,Kejz; tRec pr; scanf("%d ",&Kejz); for (kejz=1;kejz<=Kejz;kejz++) { scanf("%d %d %d ",&B,&G,&N); for (i=0;i=0;i--) { next[i]=seen[tovary[i]]; seen[tovary[i]]=i; } init(); if (kejz>1) printf("\n"); printf("Case %d:\n",kejz); for (ev=0;ev