Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int numOfCars, cap, arrival, departure, indexA, t;
- pair<int, int> cars[10100];
- stack<int, int> parking_lot;
- string answer;
- int main() {
- scanf("%d %d", &numOfCars, &cap);
- while (numOfCars != 0 && cap != 0) {
- answer = "Sim";
- for (int i = 0; i < numOfCars; i++) {
- scanf("%d %d", &arrival, &departure);
- cars[i] = make_pair(arrival, departure);
- }
- indexA = 0;
- while (indexA < numOfCars || parking_lot.size() <= cap) {
- // Tem alguem querendo sair?
- while (!parking_lot.empty() && parking_lot.top().second <= t) {
- // O cara ta atrasado, deu merda
- if (parking_lot.top().second < t) {
- answer = "Nao";
- indexA = numOfCars;
- break;
- } else {
- parking_lot.pop(); // o cara sai normalmente
- }
- }
- // Tem alguem querendo entrar?
- while (indexA < numOfCars && cars[indexA].first <= t) {
- parking_lot.push(cars[indexA]);
- indexA++;
- }
- t++;
- }
- if (parking_lot.size() > cap)
- answer = "Nao";
- cout << answer << endl;
- scanf("%d %d", &numOfCars, &cap);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement