19022022-12-08 13:30:11peterRendőrségi Üldözés 4cpp17Accepted 100/100606ms238644 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int varakozas(int ido, int periodus)
{
	int ret = 2 * periodus - (ido % (2 * periodus)) <= periodus ? 2 * periodus - (ido % (2 * periodus)) : 0;
	return ret;
}



int main()
{
	int n, r, t, l;
	scanf("%d %d %d %d", &n, &r, &t, &l);

	int* x = (int*)malloc(sizeof(int) * (n + 1));
	x[0] = 0;
	for (int i = 1; i < n + 1; i++)
	{
		scanf("%d", &x[i]);
	}

	int** sols = (int**)malloc(sizeof(int*) * (r + 1));
	for (int i = 0; i < r + 1; i++)
	{
		sols[i] = (int*)malloc(sizeof(int) * (n + 1));
		sols[i][0] = 0;
	}

	for (int i = 1; i < n + 1; i++)
	{
		sols[0][i] = sols[0][i - 1] + x[i] - x[i - 1] + varakozas(sols[0][i - 1] + x[i] - x[i - 1], t);
	}
	for (int i = 1; i < r + 1; i++)
	{
		for (int j = 1; j < n + 1; j++)
		{
			int var = sols[i][j - 1] + x[j] - x[j - 1] + varakozas(sols[i][j - 1] + x[j] - x[j - 1], t);
			int atmegy = sols[i - 1][j - 1] + x[j] - x[j - 1];
			sols[i][j] = var < atmegy ? var : atmegy;
		}
	}


	
	printf("%d", sols[r][n] + l - x[n]);
	
	free(x);
	for (int i = 0; i < r + 1; i++)
	{
		free(sols[i]);
	}
	free(sols);
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1236 KiB
2Accepted2ms1560 KiB
subtask210/10
3Accepted2ms1604 KiB
4Accepted2ms1808 KiB
5Accepted2ms2056 KiB
6Accepted2ms2308 KiB
7Accepted2ms2472 KiB
subtask315/15
8Accepted2ms2332 KiB
9Accepted2ms2400 KiB
10Accepted2ms2372 KiB
11Accepted2ms2556 KiB
subtask415/15
12Accepted2ms2852 KiB
13Accepted2ms2792 KiB
14Accepted2ms2612 KiB
15Accepted2ms2768 KiB
subtask525/25
16Accepted2ms2884 KiB
17Accepted2ms2816 KiB
18Accepted2ms3172 KiB
19Accepted2ms3120 KiB
20Accepted2ms3308 KiB
subtask615/15
21Accepted2ms2916 KiB
22Accepted2ms3312 KiB
23Accepted2ms3408 KiB
24Accepted2ms3500 KiB
25Accepted3ms3788 KiB
subtask720/20
26Accepted9ms6076 KiB
27Accepted24ms11564 KiB
28Accepted64ms27296 KiB
29Accepted210ms82132 KiB
30Accepted606ms238644 KiB