#include using namespace std; class Animal { public: Animal(char t, int s, int d); int id; int s; int d; void print(); }; Animal::Animal(char t, int _s, int _d) { if (t == 'M' || t == 'D') { id = 0; } else { id = 1; } s = _s; d = _d; } void Animal::print() { cout << id << " " << s << " " << d << endl; } bool comp_s (Animal* i, Animal* j) { return i->s < j->s; } bool comp_d (Animal* i, Animal* j) { return i->d < j->d; } void print_animals(vector animals) { for (int i=0; iid << " " << animal->s << " " << animal->d << endl; } } void print_table(vector>& end_times) { for (int i=0; i& animals) { sort(animals.begin(), animals.end(), comp_s); stable_sort(animals.begin(), animals.end(), comp_d); } vector minimumZooNumbers(vector& animals) { // Return a list of length n consisting of the answers sort_animals(animals); //print_animals(animals); vector> end_times(2, vector(animals.size())); vector last_index(2); for (auto const animal : animals) { int id = animal->id; int other_id = 1 - id; int s = animal->s; int d = animal->d; end_times[id][last_index[id]] = d; last_index[id] += 1; if (last_index[other_id] >= last_index[id]) { int other_end_time = end_times[other_id][last_index[id]-1]; while (other_end_time!= 0 && other_end_time <= s) { end_times[id][last_index[id]] = d; last_index[id] += 1; other_end_time = end_times[other_id][last_index[id]-1]; } } } //print_table(end_times); vector ret; for (int i=0; i> cases; for(int a0 = 0; a0 < cases; a0++){ int num_zoos; int num_animals; cin >> num_zoos >> num_animals; vector t(num_animals); for(int t_i = 0; t_i < num_animals; t_i++){ cin >> t[t_i]; } vector s(num_animals); for(int s_i = 0; s_i < num_animals; s_i++){ cin >> s[s_i]; } vector d(num_animals); for(int d_i = 0; d_i < num_animals; d_i++){ cin >> d[d_i]; } vector animals; for(int i = 0; i < num_animals; i++){ Animal* cur = new Animal(t[i], s[i], d[i]); animals.push_back(cur); } vector result = minimumZooNumbers(animals); for (ssize_t i = 0; i < result.size(); i++) { cout << result[i] << (i != result.size() - 1 ? " " : ""); } cout << endl; } return 0; }