Untitled

mail@pastecode.io avatar
unknown
plain_text
10 days ago
1.3 kB
2
Indexable
Never
#include <unordered_map>
#include <set>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstring>

using namespace std;

struct cmp{
	bool operator()(pair<int, int> a, pair<int, int> b) {
		return a.second < b.second;
	}
};

set<pair<int, int>, cmp> se;
unordered_map<int, int> mp;
unordered_map<int, int> q;
vector<int> parking;

int baseTime, baseFee, unitTime, unitFee, capacity;

void init(int mBaseTime, int mBaseFee, int mUnitTime, int mUnitFee, int mCapacity) {
	parking.clear();
	se.clear();
	mp.clear();

	baseTime = mBaseTime;
	baseFee = mBaseFee;
	unitFee = mUnitFee;
	unitTime = mUnitTime;
	capacity = mCapacity;
	return;
}

int arrive(int mTime, int mCar) {
	int capaCur = mp.size();
	if(capaCur > capacity) { //queue
		se.insert(make_pair(mCar, mTime));
		q[mCar] = mTime;
	} 
	else { // go to parking
		mp[mCar] = mTime;
	}
	return se.size();
}

int leave(int mTime, int mCar) {
	int res = 0;
	if(mp.find(mCar) == mp.end()) { //K co trong parking
		auto it = se.find(make_pair(mCar, q[mCar]));
		se.erase(it);
		return -1;
	} 
	else { // co trong parking
		int t = mp[mCar];
		if(t <= baseTime) {
			res = baseFee;
			return res;
		} 
		else {
			res = 5000 + ((t - baseTime) / unitTime) * unitFee;
			return res;
		}
	}
	return 0;
}
Leave a Comment