Submission #378616

#TimeUsernameProblemLanguageResultExecution timeMemory
378616joylintpGift (IZhO18_nicegift)C++17
30 / 100
2094 ms336720 KiB
#include<bits/stdc++.h> using namespace std; //#pragma gcc optimize("Ofast,unroll-loops") //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native") //#define int long long //#define double long double #define MP make_pair #define F first #define S second #define MOD 1000000007 signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; int A; priority_queue<pair<int, int>> pq; for (int i = 1; i <= N; i++) cin >> A, pq.push(MP(A, i)); vector<vector<int>> ans; while (pq.size() >= K) { ans.push_back({1}); vector<pair<int, int>> v; for (int i = 0; i < K; i++) ans.back().push_back(pq.top().S), v.push_back(pq.top()), pq.pop(); for (auto &p : v) { p.F--; if (p.F) pq.push(p); } } if (pq.empty()) { cout << ans.size() << '\n'; for (auto v : ans) { for (int i : v) cout << i << ' '; cout << '\n'; } } else cout << "-1\n"; return 0; } // * * ***** * * * * **** **** **** ** ** // * * * ** * * * * * * * * * * * // ***** ***** * * * * * * **** * * * * // * * * * ** * * * * * * ***** * // * * ***** * * *** **** * * **** * ***** // ***** ***** * * * ***** * * ***** ***** // * * * * * * * ** * * * * // * * * ***** * * * * * * ***** // * * * * * * * * ** * * // **** ***** * ***** ***** * * * *

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while (pq.size() >= K)
      |            ~~~~~~~~~~^~~~
#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...