比赛 20250904开学热身赛 评测结果 AAAAA
题目名称 内存分配 最终得分 100
用户昵称 淮淮清子 运行时间 0.185 s
代码语言 C++ 内存使用 3.74 MiB
提交时间 2025-09-04 21:31:26
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e9 + 5;

struct node{
    int m, p;
};

queue<node> wq;
set<pair<int, int>> a;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
int n, t, m, p, cnt, en;

bool Insert(int t, int m, int p){
    for(auto it = a.begin(); it != a.end(); it ++){
        auto nt = next(it);
        int ifi = it->first, ise = it->second, nfi = nt->first;
        if(nt != a.end() && (nfi - (ifi + ise)) >= m){
            a.insert({ifi + ise, m});
            q.push({t + p, ifi + ise});
            return true;
        }
    }
    return false;
}

void Init(int t){
    while(!q.empty() && t >= q.top().first){
        int tmp = q.top().first; en = tmp;
        while(!q.empty() && q.top().first == tmp){
            pair<int, int> now = q.top(); q.pop();
            a.erase(a.lower_bound({now.second, 0}));
        }
        while(!wq.empty()){
            node now = wq.front();
            if(Insert(tmp, now.m, now.p)) wq.pop();
            else break;
        }
    }
}

int main() {
    freopen("memory.in", "r", stdin);
    freopen("memory.out", "w", stdout);
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    a.insert({-1, 1}); a.insert({n, 1});
    while(cin >> t >> m >> p){
        if(t == 0 && m == 0 && p == 0) break;
        Init(t);
        if(!Insert(t, m, p)){
            wq.push({m, p});
            cnt ++;
        }
    }
    Init(MAXN);
    cout << en << '\n' << cnt << '\n';
    return 0;
}