其它系列
被队友带飞了,我是废物。
水贪心。
先按 排序,然后一个一个点加入,记录 的和,设为 ,那么当 时就需要找前面的最小 的模块减去(相当于是删去了,数是肯定是负数),然后计数器加 ,最后输出答案即可。
直接暴力会 TLE,所以我们用一个堆维护即可。
Code
#include <bits/stdc++.h>
#include <queue>
using namespace std;
#define int long long
#define rep(i, s, t) for (int i = s; i <= t; i++)
#define pre(i, s, t) for (int i = s; i >= t; i--)
const int N = 2e5 + 2;
int n, tot, res;
priority_queue<int, vector<int>, greater<int>> q;
struct node { int w, s, t; } a[N];
bool cmp(node &x, node &y) { return x.t < y.t; }
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n) cin >> a[i].w >> a[i].s >> a[i].t;
sort(a + 1, a + n + 1, cmp);
rep(i, 1, n) {
tot += a[i].s - a[i].w;
q.push(a[i].s - a[i].w);
while (tot < 0) tot -= q.top(), q.pop(), res++;
}
cout << res << '\n';
return 0;
}