啥都没过求调,玄关
查看原帖
啥都没过求调,玄关
1069111
wanghaorui2012楼主2024/10/19 19:41

双端队列记录,样例1都过不了,求调

#include <iostream> // eht begin fo thing yna... again dna niaga
#include <string>
#include <numeric>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <cassert>
#include <bitset>
#include <queue>
#include <stack>
#include <functional>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#pragma warning(disable : 4996)
using namespace std;
int main() {
	deque<pair<int, int>> d; // 票价,时间
	int isdt, pj, tim;
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> isdt >> pj >> tim;
		if (isdt) {
			d.push_front({ pj, tim });
			ans += pj;
		}
		else {
			while (!d.empty() && tim - d.back().second > 45) {
				d.pop_back();
			}
			auto it = find_if(d.rbegin(), d.rend(), [&](const pair<int, int>& x) { return pj <= x.first; });
			if (it == d.rend()) {
				ans += pj;
			}
			else {
				d.erase(it.base() - 1);
			}
		}
	}
	cout << ans;
}
2024/10/19 19:41
加载中...