Submission #878265

# Submission time Handle Problem Language Result Execution time Memory
878265 2023-11-24T07:50:48 Z The_Samurai Gift (IZhO18_nicegift) C++17
0 / 100
96 ms 21700 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &x: a) cin >> x;
    if (k == 2 and accumulate(a.begin(), a.end(), 0ll) <= 1e5) {
        priority_queue<pair<ll, int>> pq;
        for (int i = 0; i < n; i++) pq.emplace(a[i], i);
        vector<pair<int, int>> ans;
        while (pq.size() > 1) {
            auto it1 = pq.top(); pq.pop();
            auto it2 = pq.top(); pq.pop();
            ans.emplace_back(it1.second + 1, it2.second + 1);
            it1.first--; it2.first--;
            if (it1.first > 0) pq.emplace(it1); 
            if (it2.first > 0) pq.emplace(it2);
        }
        if (!pq.empty()) {
            cout << -1;
            return;
        }
        for (auto [i, j]: ans) cout << "1 " << i << ' ' << j << '\n';
        return;
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int queries = 1;
//    cin >> queries;

    for (int test_case = 1; test_case <= queries; test_case++) {
#ifdef sunnatov
        cout << "Test case: " << test_case << endl;
#endif
        solve();
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 21700 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -