Submission #69337471


Source Code Expand

#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace IO {
	template<typename T> inline void read(T &x) {
		bool f = 1;
		x = 0;
		char ch = getchar();
		while (ch < '0' || ch > '9') {
			if (ch == '-')f = 0;
			ch = getchar();
		}
		while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
		x = f ? x : -x;
	}
	template<typename T> inline void write(T x) {
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(('0' + x % 10));
	}
	template <typename T, typename ...Args> inline
	void read(T &x, Args &...args) {read(x),read(args...);}
	template<typename T> inline void write(T x, char c) {write(x), putchar(c);}
}
using namespace IO;
const int INF=1e18;

int n,k;

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>n>>k;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	vector<int> ans(n,-1);
	queue<int> s;
	priority_queue<pair<int,int>,vector<pair<int,int>>, greater<pair<int,int> > > ss;
	int x=0,idx=0;
	while(idx<n||!s.empty()||!ss.empty())
	{
		int t=min((idx<n?a[idx]:INF),(!ss.empty()?ss.top().first:INF));
		if(t==INF) break;
		while(!ss.empty()&&ss.top().first==t)
		{
			x-=c[ss.top().second];
			ss.pop();
		}
		while(idx<n&&a[idx]==t)
		{
			s.push(idx);
			++idx;
		}
		while(!s.empty())
		{
			int sum=s.front();
			if(x+c[sum]<=k)
			{
				s.pop();
				ans[sum]=t;
				x+=c[sum];
				ss.emplace(b[sum]+t,sum);
			}
			else break;
		}
	}
	for(int i=0;i<n;i++) cout<<ans[i]<<endl;
	
	return 0;
}

Submission Info

Submission Time
Task D - Long Waiting
User NingMeng_yang
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1608 Byte
Status AC
Exec Time 355 ms
Memory 16688 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 17
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3436 KiB
00-sample-02.txt AC 1 ms 3436 KiB
00-sample-03.txt AC 1 ms 3540 KiB
01-01.txt AC 104 ms 6768 KiB
01-02.txt AC 327 ms 16236 KiB
01-03.txt AC 118 ms 7260 KiB
01-04.txt AC 110 ms 6932 KiB
01-05.txt AC 346 ms 16600 KiB
01-06.txt AC 344 ms 16688 KiB
01-07.txt AC 55 ms 5132 KiB
01-08.txt AC 355 ms 16596 KiB
01-09.txt AC 321 ms 12640 KiB
01-10.txt AC 322 ms 12556 KiB
01-11.txt AC 322 ms 12552 KiB
01-12.txt AC 323 ms 12504 KiB
01-13.txt AC 321 ms 12508 KiB
01-14.txt AC 319 ms 12644 KiB