Submission #378688

#TimeUsernameProblemLanguageResultExecution timeMemory
3786882qbingxuanGift (IZhO18_nicegift)C++17
0 / 100
27 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<vector<int>> ans; while (!pq.empty()) { vector<int> v; ll x = INF; 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.push_back(v); for (int pos: v) { A[pos] -= x; if (A[pos]) pq.emplace(A[pos], pos); } } cout << ans.size() << '\n'; for (auto v: ans) { for (int i = 0; i < k; i++) cout << v[i] << (i+1==k ? '\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...