比赛 |
20250904开学热身赛 |
评测结果 |
AAAAA |
题目名称 |
内存分配 |
最终得分 |
100 |
用户昵称 |
Ruyi |
运行时间 |
0.119 s |
代码语言 |
C++ |
内存使用 |
3.69 MiB |
提交时间 |
2025-09-04 21:56:21 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n,cnt,t,m,p,a;
queue<pair<int,int> > w;
set<pair<int,int> > r;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > e;
bool as(int T,int M,int P){
for(auto i=r.begin();i!=r.end();i++){
auto j=i;++j;
if(j!=r.end()){
int s=i->first+i->second;
if(M<=j->first-s){
r.insert({s,M});
e.push({T+P,s});
return 1;
}
}
}
return 0;
}
void re(int T){
while(!e.empty()&&e.top().first<=T){
int f=e.top().first;
while(e.size()&&e.top().first==f){
auto x=e.top();e.pop();
auto i=r.lower_bound({x.second,0});
r.erase(i);
}
a=f;
while(w.size()){
auto x=w.front();
if(as(f,x.first,x.second))w.pop();
else break;
}
}
}
int main(){
freopen("memory.in","r",stdin);
freopen("memory.out","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
r.insert({-1,1});
r.insert({n,1});
while(cin>>t>>m>>p,t||m||p){
re(t);
if(!as(t,m,p))w.push({m,p}),cnt++;
}
re(2e9);
cout<<a<<'\n'<<cnt<<'\n';
return 0;
}