Submission #162917

#TimeUsernameProblemLanguageResultExecution timeMemory
162917mrboorgerGift (IZhO18_nicegift)C++14
30 / 100
2053 ms241680 KiB
//#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define ll long long #define ull unsigned long long #define ld long double #define sqr(x) (x) * (x) using namespace std; using namespace __gnu_pbds; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // LOCAL ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; priority_queue <pair <ll, int>> a; ll sum = 0; for(int i = 0; i < n; ++i) { int x; cin >> x; sum += x; if (x > 0) a.push({x, i}); } // if (sum % k > 0) // { // cout << -1; // return 0; // } vector <pair <ll, vector <int>>> ans; vector <int> cl; while(int(a.size()) >= k) { ans.pb({1, cl}); vector <pair <ll, int>> ps; for(int i = 0; i < k; ++i) { pair <ll, int> pp = a.top(); a.pop(); ans.back().S.pb(pp.S); pp.F--; if (pp.F > 0) ps.pb(pp); } for(pair <ll, int> j : ps) a.push(j); } if (!a.empty()) { cout << -1; } else { cout << int(ans.size()) << '\n'; for(int i = 0; i < int(ans.size()); ++i) { cout << ans[i].F << ' '; for(int j = 0; j < k; ++j) cout << ans[i].S[j] + 1 << ' '; cout << '\n'; } } return 0; }
#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...