Submission #332244

# Submission time Handle Problem Language Result Execution time Memory
332244 2020-12-01T18:51:31 Z vitkishloh228 Gift (IZhO18_nicegift) C++14
0 / 100
273 ms 94272 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    vector<pair<int, int>> arr;
    for (int i = 0; i < n; ++i) {
        arr.push_back({ a[i],i });
    }
    sort(arr.begin(), arr.end());
    reverse(arr.begin(), arr.end());
    vector<vector<int>> ans;
    while (!arr.empty()) {
        if (k * ans.size() > 3 * 1e6) {
            cout << "-1";
            return 0;
        }
        ans.push_back({});
        if (arr.size() < k) continue;
        for (int i = (int)arr.size() - k; i < (int)arr.size(); ++i) {
            ans.back().push_back(arr[i].second + 1);
            arr[i].first--;
        }
        while (arr.size() && arr.back().first == 0) arr.pop_back();
    }
    if (k * ans.size() > 3 * 1e6) {
        cout << "-1";
        return 0;
    }
    cout << ans.size() << endl;
    for (auto elem : ans) {
        for (auto u : elem) cout << u << ' ';
        cout << "1\n";
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:23:24: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         if (arr.size() < k) continue;
      |             ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 273 ms 94272 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -