2855 2023. 01. 30 12:55:25 zsebi Benzinkút üzemeltetés (55) cpp11 Elfogadva 55/55 3ms 4272 KiB
// benzinkut uzemeltetes.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>

#define ll long long 
using namespace std;

struct adat
{
	ll t, h,ossz,ut=0;
	bool ok = false;
};
vector<adat>x;
ll a, b,n,k;
int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> k;
	x.resize(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		cin >> x[i].t >> x[i].h;
	}
	ll maxi = 0,p;
	for (int i = 1; i <= n; ++i)
	{
		int j = i - 1;
		x[i].ossz = x[i].h;
		while (j >= 1 && x[i].t - x[j].t < k)
		{
			if (x[j].ossz > x[i].ossz)
			{

				x[i].ossz = x[j].ossz;
				x[i].ut = j;
				x[i].ok = false;
	
			}
			--j;
		}
		if (j != 0)
		{
			if (x[j].ossz+x[i].h > x[i].ossz)
			{
				x[i].ossz = x[j].ossz + x[i].h;
				x[i].ut = j;
				x[i].ok = true;
			}
		}
		
	}
	cout << x[n].ossz<<"\n";
	deque<ll>ans;
	int i = n;
	while (x[i].ut)
	{
		if(x[i].ok)
		ans.push_front(i);
			i = x[i].ut;
	}
	ans.push_front(i);
	
	cout<< ans.size() << " ";
	for (auto& e : ans)cout << e << " ";
  return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 55/55
1 Elfogadva 0/0 3ms 1828 KiB
2 Elfogadva 0/0 3ms 2224 KiB
3 Elfogadva 3/3 3ms 2268 KiB
4 Elfogadva 3/3 3ms 2476 KiB
5 Elfogadva 3/3 3ms 2544 KiB
6 Elfogadva 3/3 3ms 2816 KiB
7 Elfogadva 3/3 3ms 3056 KiB
8 Elfogadva 3/3 3ms 3032 KiB
9 Elfogadva 3/3 3ms 3248 KiB
10 Elfogadva 3/3 3ms 3472 KiB
11 Elfogadva 3/3 3ms 3556 KiB
12 Elfogadva 3/3 3ms 3560 KiB
13 Elfogadva 4/4 3ms 3568 KiB
14 Elfogadva 4/4 3ms 3904 KiB
15 Elfogadva 5/5 3ms 4136 KiB
16 Elfogadva 6/6 3ms 4008 KiB
17 Elfogadva 6/6 3ms 4272 KiB