Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
864 B
1
Indexable
Never
	#include<iostream>
	using namespace std;

	int t,m,d;
	int phut[5],giay[5], energy[5];
	int ans;
	int T[5];

	void backtrack(int k,int dis, int time, int e)
	{
		if (e < 0 || time >= ans) return;

		if (dis == d) 
		{
			if (ans > time) ans = time;
			return;
		}
	
		

		for (int i=k; i<5; i++)
		{
			backtrack(i, dis+1, time+T[i], e-energy[i]);
		}
	}


	int main()
	{
//freopen("input.txt","r",stdin);
		cin >> t;
		for (int tc=1; tc<=t; tc++)
		{
			cin >> m >> d;
			for (int i=0; i<5; i++)
			{
				cin >> phut[i] >> giay[i] >> energy[i];
			}
			
			for (int i=0; i<5; i++)
			{
				T[i] = giay[i] + phut[i]*60;
			}
			ans = 99999999;
			backtrack(0,0,0,m);

			cout << "Case #" << tc << endl;
			if (ans == 99999999) cout << "-1" << endl; 
			else
			cout << ans/60 << " " << ans%60 << endl;
		}

	}