-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path11341.cpp
More file actions
34 lines (30 loc) · 1.1 KB
/
11341.cpp
File metadata and controls
34 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
int t, n, m, classes[11][102], dp[12][102];
int solve(int i, int hoursLeft) {
if (i > n or hoursLeft == 0) return 0;
if (dp[i][hoursLeft] != -1) return dp[i][hoursLeft];
int best = -10000;
for (int hoursToStudy = 1; hoursToStudy <= hoursLeft - (n - i); hoursToStudy++) {
if (classes[i][hoursToStudy] < 5) continue;
best = max(best, classes[i][hoursToStudy] + solve(i + 1, hoursLeft - hoursToStudy));
}
return dp[i][hoursLeft] = best;
}
int main() {
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> classes[i][j];
if (n > m) { cout << "Peter, you shouldn't have played billiard that much." << endl; continue; }
memset(dp, -1, sizeof(dp));
int sol = solve(1, m);
if (sol < 5 * n) cout << "Peter, you shouldn't have played billiard that much." << endl;
else cout << fixed << setprecision(2) << "Maximal possible average mark - " <<
round((((double) sol) / n) * 100) / 100 << "." << endl;
}
return 0;
}