#include <iostream>
#include <algorithm>
using namespace std;
struct job
{
int id;
int time;
int fine;
};
bool compFunction(job a, job b){ return (a.fine < b.fine); }
void jobSequence( job* arr, int n){
// Sort all jobs according to increasing order of fine
sort(arr, arr+n, compFunction);
int result[n]; // To store final sequence
bool slot[n]; // To check if slot is free
for(int i=0; i<n; i++){ slot[i] = false; }
for(int i=0; i<n; i++){
int from = n;
if( arr[i].time < from ){ from = arr[i].time; }
for (int j = from-1; j >= 0; j--){
if( slot[j]==false ){
result[j] = i;
slot[j] = true;
break;
}
}
}
for (int i=0; i<n; i++){
if( slot[i] ){ cout << arr[result[i]].id << " ";
}}
cout << endl;
}
// Driver program to test methods
int main()
{
int totalJobs;
job* arr;
cin >> totalJobs;
arr = new job[totalJobs];
for(int i = 0; i < totalJobs; i++){
cin >> arr[i].time >> arr[i].fine;
arr[i].id = i+1;
}
jobSequence(arr, totalJobs);
return 0;
}
There is an old fairy tale where some elves secretly help an old shoemaker finish his...
1) Write a Reaction equation using 4- aminobenzenesulfulfonic acid (aniline derivative) and 8-anilino-1-naphthalenesulfonic acid (coupling agent). Write the mechanism. SYNTHESIS OF AZO DYES INTRODUCTION Humans' love of color dates back almost to prehistoric times, yet it is not actually until the modern era that the full range of the rainbow has been accessible to the majority of people irn their clothes and other textiles. Ancient or medieval times have often been described as being quite splendid with their "tyrian purple"...