Submission #99765

# Submission time Handle Problem Language Result Execution time Memory
99765 2019-03-07T01:16:15 Z choikiwon Gift (IZhO18_nicegift) C++17
0 / 100
711 ms 75952 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MN = 1000010;

int N, K;
priority_queue<pair<ll, int> > pq;
vector<vector<int> > S;
vector<ll> X;

int main() {
    std::ios::sync_with_stdio(false);

    cin >> N >> K;

    ll sum = 0;
    for(int i = 0; i < N; i++) {
        ll t; cin >> t;
        pq.push({t, i});
        sum += t;
    }

    if(sum % K) {
        cout << -1;
        return 0;
    }

    while(!pq.empty()) {
        vector<pair<ll, int> > V;
        ll tsum = 0;
        for(int i = 0; i < K; i++) {
            V.push_back(pq.top());
            tsum += pq.top().first;
            pq.pop();
        }
        sum -= tsum;

        if(pq.empty() || V.back().first < V[0].first - pq.top().first) {
            X.push_back(V.back().first);
            S.push_back(vector<int>());
            for(int i = 0; i < K; i++) {
                S.back().push_back(V[i].second);
                V[i].first -= X.back();
            }
        }
        else {
            ll d = (V.back().first + K - 2) / (K - 1);

            X.push_back(d);
            S.push_back(vector<int>());
            for(int i = 0; i < K; i++) {
                S.back().push_back(V[i].second);
                V[i].first -= X.back();
            }
        }

        for(int i = 0; i < K; i++) {
            if(V[i].first) {
                pq.push(V[i]);
                sum += V[i].first;
            }
        }
    }

    for(int i = 0; i < X.size(); i++) {
        cout << X[i] << ' ';

        for(int j = 0; j < S[i].size(); j++) {
            cout << S[i][j] + 1 << ' ';
        }
        cout << '\n';
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:67:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < X.size(); i++) {
                    ~~^~~~~~~~~~
nicegift.cpp:70:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < S[i].size(); j++) {
                        ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Same heap occurs twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Same heap occurs twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Same heap occurs twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 711 ms 75952 KB Expected int32, but "1000000000000" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Same heap occurs twice
2 Halted 0 ms 0 KB -