Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
2
Indexable
Never
#include <iostream>
#include <set>
#include <unordered_map>
#include <vector>
#include <cstring>
using namespace std;

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

unordered_map<int, int>mp;
set<pair<int, int>, cmp> se;
void init(int N, int mId[], int mTime[]) {
	mp.clear();
	se.clear();
	for(int i=0; i<N; i++) {
		se.insert(make_pair(mId[i], mTime[i]));
		mp[mId[i]] = mTime[i];
	}
	return ;
}
int add(int mId, int mTime) {
	if(mp.find(mId) != mp.end()) {
		int time_tmp = mp[mId];
		se.erase(make_pair(mId, time_tmp));
		se.insert(make_pair(mId, mTime));
		mp[mId] = mTime;
	} else {
		mp[mId] = mTime;
		se.insert(make_pair(mId, mTime));
	}
	return mp.size();
}

int remove(int K) {
	for(int i=0; i<K; i++) {
		auto it = se.begin();
		se.erase(it);
		int key = (*it).first;
		mp[key] = 0;
	}
	return se.begin()->first;
}
int produce(int M) {
	int curTime, curTotal;
	auto minMachine = se.rbegin();
	for(int i=1; i<=M; i++) {
		curTotal = i;
		curTime = (*minMachine).second * i;
		if(curTotal != M) {
			for(auto it = se.begin(); it!=se.end(); it++) {
				if((*it).first != (*minMachine).first) {
					curTotal += curTime / (*it).second;
				}
			}
			if(curTotal == M) return curTime;
		}
	}
	return 0;
}
Leave a Comment