比赛 20250904开学热身赛 评测结果 TTTTT
题目名称 内存分配 最终得分 0
用户昵称 xxz 运行时间 9.992 s
代码语言 C++ 内存使用 3.57 MiB
提交时间 2025-09-04 21:55:30
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;;
int n,aaac,eet=-123456789,cnt=1;
struct node{
	int t,m,p,et;
	bool operator>(const node &a)const{
		return et>a.et;
	}
};
queue<node>q;
priority_queue<node,vector<node>,greater<node> >qq;
void read(int &x) {bool neg = false;x = 0;char ch = 0;while (ch < '0' || ch > '9') {if (ch == '-') neg = true;ch = getchar();}if (neg) {while (ch >= '0' && ch <= '9') {x = x * 10 + ('0' - ch);ch = getchar();}} else {while (ch >= '0' && ch <= '9') {x = x * 10 + (ch - '0');ch = getchar();}}return;}
node f[12345],cf[12345];
signed main(){
	freopen("memory.in","r",stdin);freopen("memory.out","w",stdout);
	read(n);
	while(1){
		// printf("!!!!!\n");
		aaac++;
		read(f[aaac].t);read(f[aaac].m);read(f[aaac].p);
		if(!f[aaac].t&&!f[aaac].m&&!f[aaac].p){
			break;
		}
		f[aaac].et=f[aaac].t+f[aaac].p;
	}
	
	for(int i=1;;i++){
		if(!qq.empty())if(qq.top().et==i){
			n+=qq.top().m;
			qq.pop();
		}
		if(!q.empty()){
			if(q.front().t==i&&n>=q.front().m){
				qq.push(q.front());
				q.pop();
			}
		}
		if(i==f[cnt].t&&n>f[cnt].m){
			n-=f[cnt].m;
			qq.push(f[cnt-1]);
		}
		if(i==f[cnt].t&&n<f[cnt].m){
			cnt++;
			q.push(f[cnt-1]);

		}
		if(cnt>aaac&&qq.empty()){
			break;
		}
		eet=i;
		// printf("!!!!!\n");
	}

	printf("%lld\n",eet);
	printf("%lld\n",cnt-1);
	return 0;
}