Submission #69332054


Source Code Expand

//# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include"atcoder/all"
using namespace atcoder;
typedef modint998244353 mi;
using namespace std;
#define all(a) a.begin(),a.end()
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
#define compress(a) sort(all(a));a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
constexpr ll mod=1000000007;
constexpr ll inf=3e18;

const int T=10000001;
vector<int>event_in[T],event_out[T*2];

struct event{
	ll timeslice;
	int io;
	int id;
};

bool operator<(const event &lhs,const event &rhs){
	if(lhs.timeslice<rhs.timeslice)return true;
	if(lhs.timeslice>rhs.timeslice)return false;
	return lhs.io<rhs.io;
}
bool operator>(const event &lhs,const event &rhs){
	if(lhs.timeslice>rhs.timeslice)return true;
	if(lhs.timeslice<rhs.timeslice)return false;
	return lhs.io>rhs.io;
}

int main(){
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n),b(n),c(n);
	rep(i,n)cin>>a[i]>>b[i]>>c[i];
	/*
	- 待ち行列から店に移動 2
	- 待ち行列に追加 1
	- 店から出る 0
	*/

	rep(i,n){
		event_in[a[i]].push_back(i);
	}
	vector<ll>ans(n);
	priority_queue<event,vector<event>,greater<event>>pq;
	queue<int>q;
	rep(i,n)pq.push({a[i],1,i});
	while(pq.size()){
		auto top=pq.top();
		//cout<<top.timeslice<<" "<<top.io<<" "<<top.id<<endl;
		pq.pop();
		if(top.io==0){
			k+=c[top.id];
		}
		else if(top.io==1){
			q.push(top.id);
		}
		while(q.size()){
			int v=q.front();
			if(k>=c[v]){
				k-=c[v];
				ans[v]=top.timeslice;
				pq.push({ans[v]+b[v],0,v});
				q.pop();
			}
			else break;
		}
	}


	rep(i,n){
		cout<<ans[i]<<endl;
	}

}

Submission Info

Submission Time
Task D - Long Waiting
User Rho17
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1932 Byte
Status AC
Exec Time 727 ms
Memory 264516 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 127 ms 3536 KiB
00-sample-02.txt AC 128 ms 3492 KiB
00-sample-03.txt AC 128 ms 3592 KiB
01-01.txt AC 365 ms 198932 KiB
01-02.txt AC 722 ms 263260 KiB
01-03.txt AC 391 ms 209416 KiB
01-04.txt AC 380 ms 204356 KiB
01-05.txt AC 663 ms 147676 KiB
01-06.txt AC 663 ms 147424 KiB
01-07.txt AC 246 ms 100592 KiB
01-08.txt AC 673 ms 147524 KiB
01-09.txt AC 671 ms 147476 KiB
01-10.txt AC 673 ms 147476 KiB
01-11.txt AC 675 ms 147592 KiB
01-12.txt AC 675 ms 148500 KiB
01-13.txt AC 689 ms 180380 KiB
01-14.txt AC 727 ms 264516 KiB