Submission #69581443


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int qcnt = 0;
struct elem_s {
int64_t t;
int id;
} q[312345 * 2];
void qadjust(int node) {
for (;;) {
int minidx = node;
int i;
for (i = 1; i <= 2; i++) {
int c = node * 2 + i;
if (c < qcnt && q[c].t < q[minidx].t) minidx = c;
}
if (minidx == node) {
if (node == 0) return;
node = (node - 1) / 2;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int qcnt = 0;
struct elem_s {
	int64_t t;
	int id;
} q[312345 * 2];

void qadjust(int node) {
	for (;;) {
		int minidx = node;
		int i;
		for (i = 1; i <= 2; i++) {
			int c = node * 2 + i;
			if (c < qcnt && q[c].t < q[minidx].t) minidx = c;
		}
		if (minidx == node) {
			if (node == 0) return;
			node = (node - 1) / 2;
		} else {
			struct elem_s temp = q[node];
			q[node] = q[minidx];
			q[minidx] = temp;
			node = minidx;
		}
	}
}

void qadd(int64_t t, int id) {
	q[qcnt++] = (struct elem_s){ t, id };
	qadjust(qcnt - 1);
}

struct elem_s qget(void) {
	struct elem_s res;
	if (qcnt <= 0) exit(42);
	res = q[0];
	if (--qcnt > 0) {
		q[0] = q[qcnt];
		qadjust(0);
	}
	return res;
}

int N, K;
int A[312345], B[312345], C[312345];

int matigyouretu[312345];

int64_t ans[312345];

int main(void) {
	int i;
	int ms = 0, me = 0;
	int ninnzuu = 0;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d%d%d", &A[i], &B[i], &C[i]) != 3) return 1;
		qadd(A[i], i);
	}
	while (qcnt > 0) {
		struct elem_s cur = qget();
		if (cur.id > 0) {
			matigyouretu[me++] = cur.id;
		} else {
			ninnzuu -= C[-cur.id];
		}
		while (ms < me && ninnzuu + C[matigyouretu[ms]] <= K) {
			ans[matigyouretu[ms]] = cur.t;
			qadd(cur.t + B[matigyouretu[ms]], -matigyouretu[ms]);
			ninnzuu += C[matigyouretu[ms]];
			ms++;
		}
	}
	for (i = 1; i <= N; i++) {
		printf("%" PRId64 "\n", ans[i]);
	}
	return 0;
}

Submission Info

Submission Time
Task D - Long Waiting
User mikecat
Language C (gcc 12.2.0)
Score 400
Code Size 1565 Byte
Status AC
Exec Time 212 ms
Memory 15896 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 0 ms 1604 KiB
00-sample-02.txt AC 0 ms 1720 KiB
00-sample-03.txt AC 0 ms 1644 KiB
01-01.txt AC 43 ms 5244 KiB
01-02.txt AC 139 ms 15896 KiB
01-03.txt AC 48 ms 5896 KiB
01-04.txt AC 43 ms 5580 KiB
01-05.txt AC 174 ms 14396 KiB
01-06.txt AC 173 ms 14336 KiB
01-07.txt AC 27 ms 3460 KiB
01-08.txt AC 185 ms 14404 KiB
01-09.txt AC 210 ms 14452 KiB
01-10.txt AC 209 ms 14380 KiB
01-11.txt AC 210 ms 14472 KiB
01-12.txt AC 211 ms 14428 KiB
01-13.txt AC 212 ms 14356 KiB
01-14.txt AC 209 ms 14380 KiB


2025-09-24 (Wed)
07:42:55 +09:00