답안 #878265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 21700 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -