Here is the condition of the problem, like the code was written, but it does not enter. Please help me understand what the problem is. According to the n processors and m tasks, determine for each of the tasks how the processor will be processed. Entrance. The number of processors n and the sequence of numbers t0,. . . , tm β 1, where ti is the time required to process the i-th task. Output. For each task, determine which processor will start processing it at what time, assuming that each task arrives at the processing of the first released processor. In this task, your goal is to implement a simulation of parallel processing of the task list. Such handlers (dispatchers) are in all operating systems. You have n processors and a sequence of m tasks. For each task given the time required for its processing. The next job goes to the first available processor (that is, if there are several available processors, then the available processor with the lowest number gets this job). Input format The first line of input contains the numbers n and m. The second contains the numbers t0,. . . , tm β 1, where ti is the time required to process the i-th task. We consider that both processors and tasks are numbered from scratch. Output format The output must contain exactly m lines: the i-th (counting from zero) line must contain the number of the process that will receive the i-th task for processing, and the time when this will occur. Limitations. 1 β€ n β€ 105; 1 β€ m β€ 105; 0 β€ ti β€ 109. The task itself and the topic of the priority queue Here is my code
#include<iostream> #include<vector> using namespace std; void sift_up(long &i, long *p){ while(i>0 && p[(i-1)/2]<=p[i]){ swap(p[i],p[(i-1)/2]); i=(i-1)/2; } } void sift_down(long &i, long &n, long *p){ long left=2*i+1; long right=2*i+2; long max = i; if(left<n && p[left]<p[max]) max=left; if(right<n && p[right]<p[max]) max=right; if(max!=i){ swap(p[max],p[i]); ch++; ans.push_back(make_pair(i, max)); sift_down(max,n,p); } } void BuildHeap(long &n, long *p){ for(long i=n/2 - 1; i >= 0; --i){ sift_down(i,n,p); } } long ExtractMax(long &n, long *p){ long Max = p[0]; swap(p[0], p[n-1]); --n; long i = 0; sift_down(i, n, p); return Max; } void Insert_x(long &x, long &n, long *p){ n++; p[n-1]=x; long i=n-1; sift_up(i,p); } int main(){ long n, m; cin>>n>>m; long *time = new long[m]; for(long i = 0; i < m; ++i) cin>>time[i]; long *process = new long[n]; vector< pair<long, long> > ans; for(long i = 0; i < n; ++i){ ans.push_back(make_pair(0, i)); process[i] = ans[i].first + time[i]; } long *temp_process = new long[n]; BuildHeap(n, process); long n_fiction = n; for(long i = n_fiction; i < m; ++i){ ans.push_back(make_pair(process[0], i % n_fiction)); process[0] = ans[i].first + time[i]; BuildHeap(n_fiction, process); } for(long i = 0; i < ans.size(); ++i) cout<<ans[i].second<<' '<<ans[i].first<<endl; }