Submission #332246

# Submission time Handle Problem Language Result Execution time Memory
332246 2020-12-01T18:56:37 Z vitkishloh228 Gift (IZhO18_nicegift) C++14
0 / 100
249 ms 86652 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    deque<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.front().first == 0) arr.pop_front();
    }
    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:24:24: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |         if (arr.size() < k) continue;
      |             ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 82480 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 82480 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 82480 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 249 ms 86652 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 82480 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -