답안 #908159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908159 2024-01-16T08:50:13 Z daoquanglinh2007 Gift (IZhO18_nicegift) C++17
100 / 100
769 ms 104104 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define isz(a) (int)(a).size()
 
const int NM = 1e6;
 
int N, K, a[NM+5];
priority_queue <pii> Q;
vector <pair <int, vector <int> > > ans;
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	int sum = 0, mx = 0;
	for (int i = 1; i <= N; i++){
		cin >> a[i];
		sum += a[i];
		mx = max(mx, a[i]);
		Q.push(mp(a[i], i));
	}
	if (sum%K != 0 || mx > sum/K){
		cout << -1;
		return 0;
	}
	while (!Q.empty()){
		pair <int, vector <int> > P = mp(0, vector <int>(0));
		for (int i = 1; i <= K; i++){
			P.se.push_back(Q.top().se);
			Q.pop();
		}
		P.fi = a[P.se[K-1]];
		if (!Q.empty()){
			P.fi = min(P.fi, sum/K-Q.top().fi);
		}
		for (int i = 0; i < K; i++){
			a[P.se[i]] -= P.fi;
			if (a[P.se[i]] > 0) Q.push(mp(a[P.se[i]], P.se[i]));
		}
		sum -= P.fi*K;
		ans.push_back(P);
	}
	cout << isz(ans) << '\n';
	for (int i = 0; i < isz(ans); i++){
		cout << ans[i].fi << ' ';
		for (int x : ans[i].se) cout << x << ' ';
		cout << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 1 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 1 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 1 ms 344 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 17 ms 5848 KB n=50000
12 Correct 17 ms 5592 KB n=50000
13 Correct 1 ms 348 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 344 KB n=623
16 Correct 2 ms 600 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 1 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 1 ms 344 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 17 ms 5848 KB n=50000
12 Correct 17 ms 5592 KB n=50000
13 Correct 1 ms 348 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 344 KB n=623
16 Correct 2 ms 600 KB n=973
17 Correct 1 ms 344 KB n=989
18 Correct 1 ms 344 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 82648 KB n=1000000
2 Correct 241 ms 50528 KB n=666666
3 Correct 139 ms 28940 KB n=400000
4 Correct 92 ms 21568 KB n=285714
5 Correct 6 ms 1504 KB n=20000
6 Correct 55 ms 12736 KB n=181818
7 Correct 3 ms 988 KB n=10000
8 Correct 3 ms 856 KB n=6666
9 Correct 2 ms 604 KB n=4000
10 Correct 3 ms 604 KB n=2857
11 Correct 1 ms 536 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 1 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 1 ms 344 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 17 ms 5848 KB n=50000
12 Correct 17 ms 5592 KB n=50000
13 Correct 1 ms 348 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 344 KB n=623
16 Correct 2 ms 600 KB n=973
17 Correct 1 ms 344 KB n=989
18 Correct 1 ms 344 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
23 Correct 380 ms 82648 KB n=1000000
24 Correct 241 ms 50528 KB n=666666
25 Correct 139 ms 28940 KB n=400000
26 Correct 92 ms 21568 KB n=285714
27 Correct 6 ms 1504 KB n=20000
28 Correct 55 ms 12736 KB n=181818
29 Correct 3 ms 988 KB n=10000
30 Correct 3 ms 856 KB n=6666
31 Correct 2 ms 604 KB n=4000
32 Correct 3 ms 604 KB n=2857
33 Correct 1 ms 536 KB n=2000
34 Correct 12 ms 4568 KB n=23514
35 Correct 12 ms 4568 KB n=23514
36 Correct 2 ms 348 KB n=940
37 Correct 0 ms 456 KB n=2
38 Correct 32 ms 7136 KB n=100000
39 Correct 32 ms 7108 KB n=100000
40 Correct 1 ms 348 KB n=10
41 Correct 1 ms 348 KB n=100
42 Correct 2 ms 604 KB n=1000
43 Correct 468 ms 94636 KB n=1000000
44 Correct 769 ms 104104 KB n=1000000
45 Correct 458 ms 67704 KB n=666666
46 Correct 257 ms 38008 KB n=400000
47 Correct 8 ms 1116 KB n=2336
48 Correct 450 ms 57836 KB n=285714
49 Correct 403 ms 47496 KB n=181818
50 Correct 21 ms 4976 KB n=40000
51 Correct 10 ms 1752 KB n=20000
52 Correct 7 ms 992 KB n=10000
53 Correct 41 ms 4436 KB n=6666
54 Correct 4 ms 604 KB n=4000
55 Correct 165 ms 16224 KB n=2857
56 Correct 4 ms 600 KB n=2000