Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
0
Indexable
Never
#include<iostream>
using namespace std;
int minThoigian;
int s;
int arr[5][2];
int enery;
void BT(int kieuchay, int quangduong, int thoigian, int nangluong){
	if(nangluong > enery){
		return;
	}
	if(thoigian > minThoigian){
		return;
	}

	if(quangduong >= s){
		if(thoigian < minThoigian){
			minThoigian = thoigian;
		}
		return;
	}

	for (int i = kieuchay; i < 5; i++)
	{
		BT(i, quangduong+1, thoigian+arr[i][0], nangluong+arr[i][1]);
	}
}
int main(int argc, char** argv)
{
	int test_case;
	int T;
	int Answer;
	int ph, giay, e;
//	freopen("input.txt", "r", stdin);
	cin >> T;
	for(test_case = 1; test_case <= T; ++test_case)
	{
		cin >> enery >> s;
		for (int i = 0; i < 5; i++)
		{
			cin >> ph >> giay >> e;
			arr[i][0] = ph*60+giay;
			arr[i][1] = e;
		}
		Answer = 0;
		minThoigian = 100000;
		BT(0, 0, 0, 0);
		if(minThoigian != 100000){
			ph = minThoigian/60;
			giay = minThoigian%60;
			cout << "Case #" << test_case << endl << ph << " " << giay << endl;
		}else{
		cout << "Case #" << test_case << endl << -1 << endl;
		}

	}
	return 0;
}