Submission #378693

#TimeUsernameProblemLanguageResultExecution timeMemory
3786932qbingxuanGift (IZhO18_nicegift)C++17
7 / 100
26 ms5476 KiB
#include <bits/stdc++.h> #ifdef local #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #define debug(a...) qqbx(#a, a) template <typename ...T> void qqbx(const char *s, T ...a) { int cnt = sizeof...(T); ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n"))); } #else #define safe ((void)0) #define debug(...) ((void)0) #endif // local #define all(v) begin(v),end(v) using namespace std; using ll = int64_t; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; const int maxn = 100025, inf = 1e9; const ll INF = 1e18; ll A[maxn]; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, k; cin >> n >> k; max_heap<pair<ll,int>> pq; for (int i = 1; i <= n; i++) { cin >> A[i]; pq.emplace(A[i], i); } vector<pair<ll,vector<int>>> ans; while (!pq.empty()) { vector<int> v; ll x = 0; for (int t = 0; t < k; t++) { if (pq.empty()) return cout << -1 << '\n', 0; auto [y, j] = pq.top(); pq.pop(); v.push_back(j); x = y; } ans.emplace_back(x, v); for (int pos: v) { A[pos] -= x; if (A[pos]) pq.emplace(A[pos], pos); } } cout << ans.size() << '\n'; for (auto [x, v]: ans) { cout << x; for (int u: v) cout << ' ' << u; cout << '\n'; } }
#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...