30分求助(用堆做的)
查看原帖
30分求助(用堆做的)
482347
ZZQF5677楼主2022/10/14 21:06
#include <bits/stdc++.h>
using namespace std;
long long n;
bool op;
long long m;
long long t;
long long ans;
//queue<long long> yxdl;
struct Node {
	long long money, times;
	bool operator < (const Node & b) const {
		if (b.money == money) {
			return times < b.times;
		}
		return money < b.money;
	}
};
set <Node> q;
int main() {
	cin >> n;
	while (n--) {
		cin >> op >> m >> t;
		
		if (op == 0) {
			ans = ans + m;
			q.insert({m, t});
		} else {
			
			set<Node>::iterator it = q.lower_bound({m, t - 45});
			if (it == q.end()) {
				ans = ans + m;
			}else {
				if (t - (it -> times) <= 45/* && m <= (it -> money)*/) {
					q.erase(it);
				} else {
					ans = ans + m;
				}
			}
		}
		
	}
	cout << ans << "\n";
	return 0;
}
/*
15
0 1 1
0 1 2
0 1 3
0 2 1
0 2 2
0 1 5
0 2 3
0 1 6
0 2 5
0 1 7
0 2 8
0 1 8
0 2 9
0 1 9
0 3 1
*/
2022/10/14 21:06
加载中...