#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 4;
struct node {
int a, b, c;
bool operator < (const node &p) const {
return a > p.a;
}
} s[N];
int cmp(node &p, node &q) {
return p.b > q.b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int x, n;
cin >> x >> n;
for (int i = 0; i < n; i++) {
cin >> s[i].a >> s[i].b >> s[i].c;
}
sort(s, s + n, cmp); // 按保质期降序排序
priority_queue<node>q; // 堆顶为未过期的之中价格最小的
int cur = 0;
ll ans = 0;
q.push(s[cur++]);
while(!q.empty() && x > 0) {
while(cur < n && s[cur].b >= x) {
q.push(s[cur++]);
}
node t = q.top();
q.pop();
x--;
ans += t.a;
t.c--;
if (t.c > 0) {
q.push(t);
}
}
if (x > 0) {
cout << -1;
} else {
cout << ans;
}
return 0;
}
第十二届蓝桥杯国赛_巧克力_堆
最新推荐文章于 2024-03-31 16:33:04 发布