답안 #644410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644410 2022-09-24T16:09:03 Z Do_you_copy Gift (IZhO18_nicegift) C++17
7 / 100
858 ms 76572 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
#define pb push_back
const int maxN = 1e6 + 10;
const int maxOP = 3e6;
int n, k;
int a[maxN];
priority_queue <pii> PQ;

vector <vector <int>> e;
void Init(){
    cin >> n >> k;
    ll sum = 0;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        sum += a[i];
        PQ.push({a[i], i});
    }
    for (int i = 1; i * k <= maxOP; ++i){
        vector <int> pos;
        for (int j = 0; j < k; ++j){
            pos.pb(PQ.top().se);
            PQ.pop();
        }
        int add = a[pos.back()];
        add = min(add, sum / k - PQ.top().fi);
        if (!add) break;
        sum -= add * k;
        e.pb({a[pos.back()]});
        for (int j = 0; j < k; ++j){
            e.back().pb(pos[j]);
            a[pos[j]] -= add;
        }
        for (int j = 0; j < k; ++j){
            PQ.push({a[pos[j]], pos[j]});
        }
    }
    for (int i = 1; i <= n; ++i){
        if (a[i]){
            cout << -1; return;
        }
    }
    cout << e.size() << "\n";
    for (auto &i: e){
        for (auto &j: i) cout << j << " ";
        cout << "\n";
    }
}

signed main() {
    Init();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 308 KB n=3
4 Correct 0 ms 304 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 308 KB n=3
4 Correct 0 ms 304 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 0 ms 212 KB n=8
9 Incorrect 1 ms 212 KB Taken too much stones from the heap
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 308 KB n=3
4 Correct 0 ms 304 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 0 ms 212 KB n=8
9 Incorrect 1 ms 212 KB Taken too much stones from the heap
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 858 ms 76572 KB n=1000000
2 Correct 540 ms 42572 KB n=666666
3 Correct 323 ms 24820 KB n=400000
4 Incorrect 212 ms 17056 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 308 KB n=3
4 Correct 0 ms 304 KB n=4
5 Correct 1 ms 212 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 0 ms 212 KB n=8
9 Incorrect 1 ms 212 KB Taken too much stones from the heap
10 Halted 0 ms 0 KB -