Submission #41585

#TimeUsernameProblemLanguageResultExecution timeMemory
41585cheater2kGift (IZhO18_nicegift)C++14
49 / 100
665 ms65652 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;

int n, k;
long long a[N];
long long sum;
long long X;
vector < vector <int> > vres;

int lcm(int x, int y) { // n * k <= 2e6
    int g = __gcd(x, y);
    return x * (y / g);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i], sum += a[i];
    }
    bool equal = true;
    for (int i = 2; i <= n; ++i) equal &= (a[i] == a[1]);
    
    assert(sum <= 1e5 || equal);
    if (sum % k != 0) return printf("-1\n"), 0;

    priority_queue < pair<long long, int> > pq;
    for (int i = 1; i <= n; ++i) pq.push(make_pair(a[i], i));

    if (equal) X = sum / lcm(n, k); else X = 1;

    while(!pq.empty()) {
        int taken = 0;
        vector<int> cur;
        while(!pq.empty() && taken < k) {
            int pos = pq.top().second; pq.pop();
            cur.push_back(pos);
            a[pos] -= X;
            ++taken;
        }

        if (taken != k) return printf("-1\n"), 0;
        for (int pos : cur) {
            if (a[pos] > 0) {
                pq.push(make_pair(a[pos], pos));
            }
        }
        vres.push_back(cur);
    }

    printf("%d\n", vres.size());
    for (auto &v : vres) {
        printf("%lld ", X); // X
        for (int &pos : v) printf("%d ", pos); printf("\n");
    }
}

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:53:31: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", vres.size());
                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...