답안 #908157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908157 2024-01-16T08:49:50 Z daoquanglinh2007 Gift (IZhO18_nicegift) C++17
30 / 100
21 ms 7112 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 = 1e5;
 
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 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 1 ms 348 KB n=8
9 Correct 1 ms 348 KB n=14
10 Correct 1 ms 348 KB n=11
11 Correct 18 ms 4056 KB n=50000
12 Correct 16 ms 3800 KB n=50000
13 Correct 1 ms 348 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 1 ms 348 KB n=8
9 Correct 1 ms 348 KB n=14
10 Correct 1 ms 348 KB n=11
11 Correct 18 ms 4056 KB n=50000
12 Correct 16 ms 3800 KB n=50000
13 Correct 1 ms 348 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
17 Correct 1 ms 600 KB n=989
18 Correct 1 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 344 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 7112 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 1 ms 348 KB n=8
9 Correct 1 ms 348 KB n=14
10 Correct 1 ms 348 KB n=11
11 Correct 18 ms 4056 KB n=50000
12 Correct 16 ms 3800 KB n=50000
13 Correct 1 ms 348 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
17 Correct 1 ms 600 KB n=989
18 Correct 1 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 344 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
23 Runtime error 21 ms 7112 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -