結果

問題 No.1715 Dinner 2
ユーザー 👑 ygussanyygussany
提出日時 2021-10-10 14:30:41
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,044 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 31,080 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 11:33:06
合計ジャッジ時間 1,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(int n, data x[])
{
	static data y[1001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, D, P[1001], Q[1001];
	data d[1001];
	scanf("%d %d", &N, &D);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &(P[i]), &(Q[i]));
		d[i-1].key = Q[i] - P[i];
		d[i-1].id = i;
	}
	merge_sort(N, d);

	int j, k, l = 1, r = 1 << 27, m, last;
	while (l < r) {
		m = (l + r) / 2;
		for (i = 1, k = 0, last = N; i <= D; i++) {
			for (j = N - 1; j >= 0; j--) {
				if (j == last) continue;
				if (k - P[d[j].id] >= -m) break;
			}
			if (j < 0) break;
			last = j;
			j = d[j].id;
			k += Q[j] - P[j];
		}
		if (i > D) r = m;
		else l = m + 1;
	}
	printf("%d\n", -l);
	fflush(stdout);
	return 0;
}
0