Untitled
unknown
plain_text
2 years ago
829 B
4
Indexable
#include<iostream> using namespace std; int T, M, D, m, s, p, runType[5][2], ans, runTime; void bt(int d, int power) { if (runTime >= ans || power > M) return; if (d == D && power <= M) { ans = ans < runTime ? ans : runTime; return; } for (int i = 0; i < 5; i++) { runTime += runType[i][0]; bt(d + 1, power + runType[i][1]); runTime -= runType[i][0]; } } int main() { //freopen("TextFile1.txt", "r", stdin); cin >> T; for (int tc = 1; tc <= T; tc++) { cin >> M >> D; for (int i = 0; i < 5; i++) { cin >> m >> s >> p; runType[i][0] = m * 60 + s; runType[i][1] = p; } ans = 10000000; runTime = 0; bt(0, 0); if(ans == 10000000) cout << "Case #" << tc << endl << -1 << endl; cout << "Case #" << tc << endl << ans / 60 << " " << ans % 60 << endl; } return 0; }
Editor is loading...
Leave a Comment