Submission #41576

#TimeUsernameProblemLanguageResultExecution timeMemory
41576cheater2kGift (IZhO18_nicegift)C++14
30 / 100
156 ms30652 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, k; long long a[N]; long long sum; vector < vector <int> > vres; 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]; } assert(sum <= 1e5); if (sum % k != 0) return printf("-1\n"), 0; priority_queue < pair<int,int> > pq; for (int i = 1; i <= n; ++i) pq.push(make_pair(a[i], i)); 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]; ++taken; } if (taken != k) return printf("-1\n"), 0; for (int pos : cur) { if (a[pos]) { pq.push(make_pair(a[pos], pos)); } } vres.push_back(cur); } printf("%d\n", vres.size()); for (auto &v : vres) { printf("1 "); // X for (int &pos : v) printf("%d ", pos); printf("\n"); } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:43: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...