Submission #335289

# Submission time Handle Problem Language Result Execution time Memory
335289 2020-12-11T20:21:41 Z limabeans Gift (IZhO18_nicegift) C++17
18 / 100
2000 ms 349104 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;







int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);


    ll n,k;
    cin>>n>>k;
    assert(k==2);
    priority_queue<pair<ll,int>> pq;
    ll sum=0;
    for (int i=1; i<=n; i++) {
	ll x;
	cin>>x;
	sum += x;
	pq.push({x,i});
    }

    if (sum%k) out(-1);

    vector<vector<int>> w;

    while (pq.size()) {
	auto cur = pq.top();
	pq.pop();

	if (pq.empty()) out(-1);
	
	auto cur2 = pq.top();
	pq.pop();
	w.push_back({cur.second,cur2.second});
	cur.first--;
	cur2.first--;
	if (cur.first) {
	    pq.push(cur);
	}
	if (cur2.first) {
	    pq.push(cur2);
	}
    }

    cout<<w.size()<<"\n";
    for (auto p: w) {
	cout<<1<<" "<<p[0]<<" "<<p[1]<<"\n";
    }
    
    
    return 0;
}
# 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 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 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 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 2 ms 1004 KB n=8
9 Correct 6 ms 1192 KB n=14
10 Correct 4 ms 1032 KB n=11
11 Correct 33 ms 4708 KB n=50000
12 Correct 33 ms 4708 KB n=50000
13 Correct 21 ms 3360 KB n=10
14 Correct 23 ms 3104 KB n=685
15 Correct 26 ms 3360 KB n=623
16 Correct 15 ms 2084 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 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 2 ms 1004 KB n=8
9 Correct 6 ms 1192 KB n=14
10 Correct 4 ms 1032 KB n=11
11 Correct 33 ms 4708 KB n=50000
12 Correct 33 ms 4708 KB n=50000
13 Correct 21 ms 3360 KB n=10
14 Correct 23 ms 3104 KB n=685
15 Correct 26 ms 3360 KB n=623
16 Correct 15 ms 2084 KB n=973
17 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 349104 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 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 2 ms 1004 KB n=8
9 Correct 6 ms 1192 KB n=14
10 Correct 4 ms 1032 KB n=11
11 Correct 33 ms 4708 KB n=50000
12 Correct 33 ms 4708 KB n=50000
13 Correct 21 ms 3360 KB n=10
14 Correct 23 ms 3104 KB n=685
15 Correct 26 ms 3360 KB n=623
16 Correct 15 ms 2084 KB n=973
17 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -