Submission #522268

#TimeUsernameProblemLanguageResultExecution timeMemory
522268vonatlusGift (IZhO18_nicegift)C++17
7 / 100
2071 ms15948 KiB
/// adil sultanov | vonat1us #pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:36777216") #include<bits/stdc++.h> #define x first #define y second #define pb push_back #define sz(x) (int) x.size() #define all(z) (z).begin(), (z).end() using namespace std; using ll = long long; using pii = pair<ll, int>; const int MOD = 1e9 + 7; const int INF = 1e9 + 1e2; void fin() { #ifdef AM freopen(".in", "r", stdin); #endif } const bool flag = 0; const int N = 1e5+10; void ma1n() { ll n, k; cin >> n >> k; vector<pii> a(n); ll sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i].x, a[i].y = i; sum += a[i].x; } if (sum%k) { cout << -1, exit(0); } vector<vector<int>> ans; while (1) { sort(all(a)); reverse(all(a)); //for (auto it : a) cout << it.x << " "; //cout << "\n"; if (a[0].x == 0) break; for (int i = 1; i < k; ++i) { if (a[i].x == 0) { cout << -1, exit(0); } } vector<int> v; ll d = a[k-1].x-(k < n && a[k].x ? a[k].x : 1ll)+1; v.pb(d-1); for (int i = 0; i < k; ++i) { a[i].x -= d; v.pb(a[i].y); } ans.pb(v); } cout << sz(ans) << "\n"; for (auto v : ans) { for (int x : v) cout << x+1 << " "; cout << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr), fin(); int ts = 1; if (flag) { cin >> ts; } while (ts--) { ma1n(); } 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...