-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTheHeartOfTheCountry.cpp
101 lines (78 loc) · 2.19 KB
/
TheHeartOfTheCountry.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <bits/stdc++.h>
template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}
template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }
using namespace std;
typedef long long Int;
typedef unsigned long long uInt;
typedef unsigned uint;
const int MAXN = 1010;
int N, M, K;
int P[MAXN];
Int S[MAXN];
set<int> G[MAXN];
bool active[MAXN];
int main(void) {
cin.tie(0);
ios_base::sync_with_stdio(false);
while (cin >> N >> K) {
if (N == 0 && K == 0) break;
for (int i = 0; i <= N; i++) {
G[i].clear();
S[i] = 0;
active[i] = 1;
}
for (int i = 0; i < N; i++) {
cin >> P[i] >> M;
for (int j = 0; j < M; j++) {
int a;
cin >> a;
G[i].insert(a);
G[a].insert(i);
}
}
vector<pair<Int, int> > q;
for (int i = 0; i < N; i++) {
S[i] = P[i];
for (auto& it : G[i]) {
S[i] += P[it];
}
q.push_back({S[i], i});
}
sort(q.begin(), q.end());
while (1) {
bool fine = false;
for (int i = 0; i < N; i++) {
int is = q[i].second;
if (!active[is]) continue;
if (S[is] < K) {
fine = true;
active[is] = 0;
for (auto& it : G[is]) {
S[it] -= P[is];
}
}
}
if (!fine) break;
}
int ans = 0;
Int cnt = 0;
//cout << "\n";
for (int i = 0; i < N; i++) {
if (S[q[i].second] >= K) {
ans += 1;
//cout << (*q.begin()).second << "\n";
cnt += P[q[i].second];
}
}
cout << ans << " " << cnt << "\n";
}
return 0;
}