Problem
Problem CO_ADD Problem - CodeChef
CODE RUSH 1.0 Contest Link:Contest Page | CodeChef
Author: Krish Murarka
Tester: Krish Murarka
Editorialist: Krish Murarka
DIFFICULTY:
EASY-Medium
PREREQUISITES:
STACK and Dynamic Array.
PROBLEM:
If you fulfill the admission of any student and there exist some people (ranked 1 or more) who have ranked earlier but haven’t arrived at the college yet, then those people are said to have missed their admission. If at some point of time there exists a set of people that have missed their admission earlier and the student who had their admission most recently among them (later than others in that set) say student X is now available then X is given the priority to get admission over any other student.
EXPLANATION:
the admission of the student who ranked first (so if a student having 1 is available then that student can get the admission) otherwise you look for the next available student.even if any student in that set Y other than X is available and X is not available then you start admissions of the people who have not yet missed their admission in their order of ranking. You are given the order in which people arrive at the college and have to print the order of their admissions.
SOLUTION
Setters Solution
using namespace std;
void solution(){
int n, x, i; cin >> n; stack<int> stack; vector<bool> vector; for (int j = 0; j < n+1; ++j){ vector.push_back(false); } i = 0; while (n--) { cin >> x; if (i < x) { cout << x << " "; while (++i < x){ stack.push(i); } } vector[x] = true; while (!stack.empty() and vector[stack.top()]) { cout << stack.top() << " "; stack.pop(); } } while (!stack.empty()){ cout << stack.top() << " "; stack.pop(); } cout << endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solution();
}