hugo_thichay

 avatar
duyvan
plain_text
a year ago
948 B
9
Indexable
//hugo_thichay
#include <iostream>
using namespace std;
#define max_int 100000000
int T, M, D, mi, se;
// min-second-energy: second = min*60second
int second[6], energy[6];
int ans;

void nhap(){
	cin >> M >> D;
	for(int i=0; i<5;i++){
		int minutes; cin >> minutes;
		int secon; cin >> secon;
		second[i] = secon + 60*minutes;
		cin >> energy[i];
	}
}
void timeFinish(int runtype, int k, int time, int uEnergy) {
	if(time > ans || uEnergy > M)
		return;
	if(k == D) {
		if (time < ans)
			ans = time;
		return;
	}
	for(int type = runtype; type < 5; type++) {
		timeFinish(type, k + 1, time + second[type], uEnergy + energy[type]);
	}
}

int main(){
	freopen("INP.txt","r",stdin);
	cin >> T;
	for(int tc=1; tc<=T; tc++){
		nhap();
		ans = max_int;
		timeFinish(0,0,0,0);
		mi = ans/60;
		se = ans%60;
		cout << "Case #" << tc << endl;
		if (ans == max_int)
			cout << "-1" << endl;
		else
			cout << ans/60 << " " << ans%60 << endl;
	}
	return 0;
}
Editor is loading...
Leave a Comment