Submission #133828

#TimeUsernameProblemLanguageResultExecution timeMemory
133828KastandaGift (IZhO18_nicegift)C++11
100 / 100
1251 ms73260 KiB
// ItnoE #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000006; int n, k; ll SM, A[N]; vector < ll > R; priority_queue < pair < ll , int > > Pq; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i ++) { scanf("%lld", &A[i]); Pq.push({A[i], i}); SM += A[i]; } if (SM % k || Pq.top().first > SM / k) return !printf("-1\n"); SM /= k; while (Pq.top().first) { vector < int > vec; for (int i = 0; i < k; i ++) vec.push_back(Pq.top().second), Pq.pop(); ll Mx = Pq.size() ? Pq.top().first : 0LL; ll X = min(A[vec.back()], SM - Mx); R.push_back(X); SM -= X; for (int i = 0; i < k; i ++) A[vec[i]] -= X, Pq.push({A[vec[i]], vec[i]}), R.push_back(vec[i]); } printf("%d\n", (int)R.size() / (k + 1)); for (int i = 0; i < (int)R.size(); i ++) { printf("%lld ", R[i]); if ((i + 1) % (k + 1) == 0) printf("\n"); } return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &A[i]);
         ~~~~~^~~~~~~~~~~~~~~
#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...