Submission #378658

# Submission time Handle Problem Language Result Execution time Memory
378658 2021-03-17T02:59:21 Z rk42745417 Gift (IZhO18_nicegift) C++17
18 / 100
2000 ms 116792 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;
	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});
	vector<tuple<int, int, int>> ans;
	auto get = [&]() {
		if(pq.empty())
			return -1;
		int w = pq.top().second;
		pq.pop();
		return w;
	};
	while(!pq.empty()) {
		int x = get(), y = get();
		if(y < 0)
			return cout << "-1\n", 0;
		ans.push_back({1, x, y});
		arr[x]--;
		arr[y]--;
		if(arr[x])
			pq.push({arr[x], x});
		if(arr[y])
			pq.push({arr[y], y});
	}
	cout << ans.size() << '\n';
	for(const auto &[v, x, y] : ans)
		cout << v << ' ' << x + 1 << ' ' << y + 1 << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 620 KB n=8
9 Correct 5 ms 684 KB n=14
10 Correct 4 ms 620 KB n=11
11 Correct 30 ms 2664 KB n=50000
12 Correct 30 ms 2536 KB n=50000
13 Correct 22 ms 1380 KB n=10
14 Correct 19 ms 1384 KB n=685
15 Correct 21 ms 1512 KB n=623
16 Correct 12 ms 1004 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 620 KB n=8
9 Correct 5 ms 684 KB n=14
10 Correct 4 ms 620 KB n=11
11 Correct 30 ms 2664 KB n=50000
12 Correct 30 ms 2536 KB n=50000
13 Correct 22 ms 1380 KB n=10
14 Correct 19 ms 1384 KB n=685
15 Correct 21 ms 1512 KB n=623
16 Correct 12 ms 1004 KB n=973
17 Incorrect 25 ms 1512 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 116792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 492 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 620 KB n=8
9 Correct 5 ms 684 KB n=14
10 Correct 4 ms 620 KB n=11
11 Correct 30 ms 2664 KB n=50000
12 Correct 30 ms 2536 KB n=50000
13 Correct 22 ms 1380 KB n=10
14 Correct 19 ms 1384 KB n=685
15 Correct 21 ms 1512 KB n=623
16 Correct 12 ms 1004 KB n=973
17 Incorrect 25 ms 1512 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -