hugothichaysol
quoc14
c_cpp
a year ago
1.2 kB
13
Indexable
caidat
#include <iostream>
using namespace std;
int n;
int mintime;
struct RunType{
int time;
int nltt;
};
RunType RunTypes[10];
int maxnl;
int mfar;
void back(int index, int sumnl, int time, int tmpfar)
{
if (index == 5)
{
sumnl += tmpfar*RunTypes[5].nltt;
time += tmpfar*RunTypes[5].time;
if (sumnl <= maxnl && time < mintime)
mintime = time;
return;
}
if (sumnl > maxnl) return;
if (time > mintime) return;
for (int i = 0; i <= tmpfar; i++)
{
back(index + 1, sumnl + i*RunTypes[index].nltt, time + i*RunTypes[index].time, tmpfar - i);
}
}
int main()
{
//freopen("input.txt","r",stdin);
int ntc;
cin >> ntc;
for (int tc=1; tc<=ntc; tc++)
{
cin >> maxnl;
cin >> mfar;
for (int i = 1; i <= 5; i++)
{
int minute, second;
cin >> minute >> second >> RunTypes[i].nltt;
RunTypes[i].time = minute * 60 + second;
}
mintime = 99999999;
back(1, 0, 0, mfar);
int rminute = mintime/60;
cout << "Case #"<<tc;
if (mintime == 99999999)
{
cout<<endl<<-1<<endl;
} else
cout <<endl<< rminute<< " "<<mintime - rminute*60 << endl;
}
return 0;
}
Editor is loading...
Leave a Comment