#include #include struct claster { int end; }; struct Pqueue { int cap,count; struct claster *h; }; void InitPqueue(struct Pqueue* pq, int ClastCount) { pq->h = (struct claster*)malloc(ClastCount * sizeof(struct claster)); pq->cap = ClastCount; pq->count = 0; } void insert(struct Pqueue *pq,int ptr) { int i; i=pq->count; pq->count=i+1; pq->h[i].end=ptr; struct claster Swap; while(i>0 && pq->h[(i-1)/2].end > pq->h[i].end) { Swap=pq->h[(i-1)/2]; pq->h[(i-1)/2]=pq->h[i]; pq->h[i]=Swap; i = (i-1)/2; } } void insert1(struct Pqueue *pq,int ptr) { int i; i=pq->count-1; pq->h[i].end=ptr; struct claster Swap; while(i>0 && pq->h[(i-1)/2].end > pq->h[i].end) { Swap=pq->h[(i-1)/2]; pq->h[(i-1)/2]=pq->h[i]; pq->h[i]=Swap; i = (i-1)/2; } } void Heapify(struct Pqueue* pq) { int l, r, j,i; struct claster swap; for(i = 0;;) { l = 2*i+1; r = l+1; j = i; if(l < pq->count && pq->h[l].end < pq->h[j].end) { j = l; } if(r < pq->count && pq->h[r].end < pq->h[j].end) { j = r; } if(i == j) { break; } swap = pq->h[i]; pq->h[i] = pq->h[j]; pq->h[j] = swap; i = j; } } int main (int argc, char const *argv[]) { int ClastCount,i,NumOfOperations=0,swap=0; scanf("%d", &ClastCount ); scanf("%d", &NumOfOperations ); struct Pqueue pq; InitPqueue(&pq, ClastCount); int time[NumOfOperations][2]; for(i = 0; i < ClastCount; i++) { scanf("%d", &time[i][0] ); scanf("%d", &time[i][1] ); time[i][1]+=time[i][0]; insert(&pq,time[i][1]); } Heapify(&pq); for (; i