Submission details
Task:Yhdistelmät
Sender:hltk
Submission time:2025-11-30 21:22:45 +0200
Language:C++ (C++20)
Status:READY
Result:17
Feedback
groupverdictscore
#10
#2ACCEPTED17
#30
#40
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4details
#20.00 s1, 3, 4details
#30.00 s1, 4details
#40.00 s1, 4details
#50.00 s1, 4details
#60.00 s1, 4details
#70.00 s1, 4details
#80.00 s1, 4details
#90.00 s1, 4details
#100.00 s1, 4details
#11ACCEPTED0.00 s2, 3, 4details
#120.00 s3, 4details
#130.00 s4details
#140.00 s4details
#150.00 s4details
#160.00 s4details
#170.00 s4details
#18ACCEPTED0.00 s1, 2, 3, 4details
#19ACCEPTED0.00 s1, 2, 3, 4details
#20ACCEPTED0.00 s4details
#210.00 s4details

Code

#include <algorithm>
#include <numeric>
#include <iostream>
#include <vector>

using namespace std;

using vi = vector<int>;
using pii = pair<int, int>;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m;
	cin >> n >> m;

	vi p(n);

	for (int i = 0; i < n; ++i) {
		cin >> p[i];
		p[i] *= 2;
	}

	vector<pair<vi, int>> o;

	for (int i = 0; i < m; ++i) {
		int k, x;
		cin >> k >> x;
		vi ks(k);
		for (int j = 0; j < k; ++j) {
			cin >> ks[j];
			ks[j]--;
		}
		if (k == 1) {
			p[ks[0]] -= x * 2;
		} else {
			o.emplace_back(ks, x);
		}
	}

	m = size(o);

	vector<vector<pii>> g(n);
	for (int i = 0; i < m; ++i) {
		auto &[v, x] = o[i];
		if (v.size() == 2) {
			g[v[0]].emplace_back(v[1], i);
			g[v[1]].emplace_back(v[0], i);
		}
	}

	vi picked(n);
	long ans = 0;

	for (;;) {
		bool f = 0;
		for (int i = 0; i < n; ++i) {
			if (picked[i]) continue;
			long c = -p[i];
			for (auto [j, oi] : g[i]) {
				if (!picked[j]) {
					c += max(0, o[oi].second - p[oi]);
				}
			}
			if (c > 0) {
				picked[i] = 1;
				for (auto [j, oi] : g[i]) {
					if (!picked[j]) {
						if (o[oi].second - p[oi] > 0) {
							picked[j] = 1;
						}
					}
				}
				f = 1;
				break;
			}
		}
		ans = 0;
		for (int i = 0; i < n; ++i) {
			if (picked[i]) {
				ans -= p[i];
				for (auto [j, oi] : g[i]) {
					if (picked[j]) {
						ans += o[oi].second;
					}
				}
			}
		}
		if (!f) {
			break;
		}
	}

	cout << ans / 2 << endl;
	cout << accumulate(begin(picked), end(picked), 0) << endl;
	for (int i = 0; i < n; ++i) {
		if (picked[i]) {
			cout << i + 1 << ' ';
		}
	}
	cout << endl;
}

Test details

Test 1

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
20 20
80 69 91 47 74 75 94 22 100 43...

correct output
446
11
2 3 5 8 10 13 14 15 17 19 20 

user output
446
11
2 3 5 8 10 13 14 15 17 19 20 

Test 2

Group: 1, 3, 4

Verdict:

input
20 20
5 42 7 18 55 64 64 83 73 44 22...

correct output
425
11
1 2 3 4 7 10 13 16 18 19 20 

user output
393
9
1 2 3 4 10 13 18 19 20 

Test 3

Group: 1, 4

Verdict:

input
20 20
30 98 55 69 40 3 95 12 64 56 3...

correct output
284
8
1 3 8 10 15 16 18 19 

user output
77
8
1 3 5 8 10 13 15 17 

Test 4

Group: 1, 4

Verdict:

input
20 20
11 44 58 8 16 52 20 43 24 31 4...

correct output
348
10
2 4 5 7 11 13 15 16 18 20 

user output
175
3
15 18 20 

Test 5

Group: 1, 4

Verdict:

input
20 20
53 44 5 37 88 36 81 47 85 97 3...

correct output
119
13
1 2 4 8 10 11 13 14 16 17 18 1...

user output
31
3
2 14 18 

Test 6

Group: 1, 4

Verdict:

input
20 20
20 27 75 94 48 62 37 55 49 67 ...

correct output
478
11
1 2 5 7 10 12 13 15 16 17 18 

user output
125
5
5 13 15 16 18 

Test 7

Group: 1, 4

Verdict:

input
20 20
32 28 67 72 32 76 53 30 47 67 ...

correct output
215
10
2 4 5 7 8 9 11 13 16 20 

user output
105
3
2 9 20 

Test 8

Group: 1, 4

Verdict:

input
20 20
39 72 74 79 49 45 73 44 37 4 7...

correct output
185
13
1 3 5 6 7 8 10 13 14 16 17 18 ...

user output
100
4
3 8 17 20 

Test 9

Group: 1, 4

Verdict:

input
20 20
41 56 65 78 2 13 17 42 83 76 9...

correct output
95
11
2 4 5 6 7 8 13 14 17 18 19 

user output
59
2
4 13 

Test 10

Group: 1, 4

Verdict:

input
20 20
43 1 20 61 25 46 2 18 36 1 85 ...

correct output
111
8
1 2 3 7 8 10 16 19 

user output
-20
4
2 10 14 20 

Test 11

Group: 2, 3, 4

Verdict: ACCEPTED

input
100 100
992248 852673 366775 737068 56...

correct output
30642743
46
3 5 6 9 11 12 15 16 17 18 21 2...

user output
30642743
46
3 5 6 9 11 12 15 16 17 18 21 2...

Test 12

Group: 3, 4

Verdict:

input
100 100
153790 361741 45017 47184 9422...

correct output
16529629
39
2 3 4 5 10 12 14 17 24 25 26 3...

user output
8762740
37
2 3 4 13 15 24 25 32 33 36 38 ...

Test 13

Group: 4

Verdict:

input
100 100
186797 446409 957173 150683 17...

correct output
14928280
62
1 2 8 9 10 11 12 14 15 16 17 2...

user output
6046403
23
8 9 10 14 17 22 24 33 37 40 41...

Test 14

Group: 4

Verdict:

input
100 100
343213 582494 707357 104682 66...

correct output
11308944
72
1 3 4 5 6 7 8 9 10 11 12 13 14...

user output
3184044
11
4 7 8 10 25 30 49 53 63 82 83 

Test 15

Group: 4

Verdict:

input
100 100
922546 12088 805566 351521 644...

correct output
3311952
10
14 17 26 29 64 65 70 76 83 95 

user output
3098811
9
14 17 29 64 65 70 76 83 95 

Test 16

Group: 4

Verdict:

input
100 100
923042 35929 531316 587665 845...

correct output
519209
6
2 18 45 61 64 86 

user output
0
0

Test 17

Group: 4

Verdict:

input
100 100
493725 218022 417464 531537 83...

correct output
1255541
11
16 19 24 29 30 50 60 62 67 74 ...

user output
906439
4
16 29 30 50 

Test 18

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
1 1
2
1 1
1

correct output
0
0

user output
0
0

Test 19

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
1 1
1
1 2
1

correct output
1
1

user output
1
1

Test 20

Group: 4

Verdict: ACCEPTED

input
100 100
1000000 1000000 1000000 100000...

correct output
0
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
0
0

Test 21

Group: 4

Verdict:

input
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
99999900
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
0
0