Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define sz(x) (int(x.size()))
- typedef tuple<int, int, int> T;
- int getint() {
- int inp;
- cin >> inp;
- return inp;
- }
- void count_conflict(
- vector<vector<T>> timetable,
- vector<int> choices,
- int& conflict,
- int& credit) {
- credit = 0;
- vector<int> cnt(24 * 5, 0);
- for (auto c : choices) {
- auto courses = timetable[c];
- for (T seg : courses) {
- int w = get<0>(seg);
- int t0 = get<1>(seg);
- int t1 = get<2>(seg);
- credit += (t1 - t0);
- int s = (w - 1) * 24 + t0;
- int e = (w - 1) * 24 + t1;
- for (int t = s; t < e; t++) {
- cnt[t] += 1;
- }
- }
- }
- conflict = 0;
- for (int c : cnt) {
- if (c > 1) {
- conflict += (c - 1);
- }
- }
- }
- void solve() {
- int N = getint();
- int K = getint();
- vector<vector<T>> timetable;
- for (int i = 0; i < N; i++) {
- int c = getint();
- vector<T> courses(c);
- for (int j = 0; j < c; j++) {
- int w = getint();
- int t0 = getint();
- int t1 = getint();
- courses[j] = T(w, t0, t1);
- }
- timetable.push_back(courses);
- }
- int ans = -1;
- for (int mask = 1; mask < (1 << N); mask++) {
- vector<int> choices;
- for (int i = 0; i < N; i++) {
- if (mask & (1 << i)) {
- choices.push_back(i);
- }
- }
- int conflict = 0, credit = 0;
- count_conflict(timetable, choices, conflict, credit);
- if (conflict <= K) {
- ans = max(ans, credit);
- }
- }
- cout << ans << endl;
- }
- int main() {
- int TC = getint();
- while (TC--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement