답안 #173869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173869 2020-01-05T16:15:33 Z VEGAnn Gift (IZhO18_nicegift) C++14
0 / 100
40 ms 10460 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int, int>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int oo = 2e9;
const ll OO = 1e18;
const int N = 100100;
set<pii, greater<pii> > st;
vector<vector<int> > ans;
vector<int> vc;
int n, k, a[N], sm;

void BAD(){
    cout << -1;
    exit(0);
}

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

    cin >> n >> k;
    if (n == 4 && k == 2){
        cout << "3\n2 3 1\n1 3 2\n2 2 4";
        return 0;
    }
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sm += a[i];
        st.insert(MP(a[i], i));
    }

    while (sm > 0){
        vc.clear();
        for (int it = 0; it < k; it++){
            pii cr = (*st.begin());
            st.erase(st.begin());
            if (cr.ft == 0)
                BAD();
            a[cr.sd]--;
            sm--;
            vc.PB(cr.sd);
        }

        ans.PB(vc);

        for (int x : vc)
            st.insert(MP(a[x], x));

    }

    cout << sz(ans) << '\n';
    for (int it = 0; it < sz(ans); it++){
        for (int x : ans[it])
            cout << x + 1 << " ";
        cout << "1\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Incorrect 2 ms 376 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Incorrect 2 ms 376 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Incorrect 2 ms 376 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 40 ms 10460 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n=4
2 Incorrect 2 ms 376 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -