Submission #378674

# Submission time Handle Problem Language Result Execution time Memory
378674 2021-03-17T03:07:16 Z rk42745417 Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 406132 KB
#include <bits/stdc++.h>
using namespace std;

using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 2e18;
const double EPS = 1e-9;
#define EMT ios::sync_with_stdio(0); cin.tie(0);

signed main() { EMT
	int n, k;
	cin >> n >> k;
	ll s = 0;
	vector<int> arr(n);
	priority_queue<pair<int, int>> pq;

	for(int i = 0; i < n; i++)
		cin >> arr[i], pq.push({arr[i], i});
	for(int i = 0; i < n; i++)
		s += arr[i];
	//if(*max_element(arr.begin(), arr.end()) == *min_element(arr.begin(), arr.end())) {
		//if(
	//}
	vector<pair<int, vector<int>>> ans;
	auto get = [&]() {
		if(pq.empty())
			return -1;
		int w = pq.top().second;
		pq.pop();
		return w;
	};
	while(!pq.empty()) {
		vector<int> tmp(k);
		for(int i = 0; i < k; i++)
			tmp[i] = get();
		if(tmp.back() < 0)
			return cout << "-1\n", 0;
		ans.push_back({1, tmp});
		for(int a : tmp) {
			arr[a]--;
			if(arr[a])
				pq.push({arr[a], a});
		}
	}
	cout << ans.size() << '\n';
	for(const auto &[x, y] : ans) {
		cout << x;
		for(int a : y)
			cout << ' ' << a;
		cout << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2101 ms 406132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -